#P8520. Fountain Road and Bench Assignment

    ID: 21688 Type: Default 1000ms 256MiB

Fountain Road and Bench Assignment

Fountain Road and Bench Assignment

In a nearby park there are nn fountains, numbered 00 to n1n-1. Each fountain is represented as a point (xi,yi)(x_i,y_i) on the 2D plane where both xix_i and yiy_i are even, and all positions are distinct. Architect Timothy is tasked with constructing some roads and placing benches. Each road must be a horizontal or vertical segment of length 22, whose endpoints are two different fountains. The roads to be built should allow a visitor to travel between any two fountains (i.e. the road network must be connected). Initially, there are no roads.

For every road, exactly one bench is to be placed and assigned (i.e. facing) to that road. Each bench must be placed at some point (a,b)(a,b) where both aa and bb are odd, and benches must be at distinct locations. Moreover, a bench at (a,b)(a,b) can only be assigned to a road whose endpoints are one of the following four points: [ {(a-1,b-1),,(a-1,b+1),,(a+1,b-1),,(a+1,b+1)}. ] For example, a bench at (3,3)(3,3) can only be assigned to one of the roads connecting (2,2)(2,2) and (2,4)(2,4), (2,4)(2,4) and (4,4)(4,4), (4,4)(4,4) and (4,2)(4,2), or (4,2)(4,2) and (2,2)(2,2).

Your task is to decide whether it is possible to construct a set of roads and assign benches so that all these conditions are met. If yes, output a valid solution. If there are multiple solutions, any one is acceptable.

inputFormat

The first line contains an integer nn (1n1051\le n\le 10^5, for example), which is the number of fountains. Each of the following nn lines contains two even integers xx and yy, representing the coordinates of a fountain. It is guaranteed that all fountain positions are distinct.

outputFormat

If a solution exists, print “YES” on the first line, followed by an integer mm on the next line representing the number of roads used (in any valid road network connecting all fountains, a spanning tree suffices, so m=n1m=n-1 if n>0n>0). Then output mm lines, each containing five space‐separated integers: uu, vv, aa, bb. Here uu and vv are the indices of the two fountains connected by the road, and (a,b)(a,b) is the position of the bench assigned to that road. If no valid solution exists, just print “NO”.

A road between two fountains is valid only if the two fountains differ by 22 in exactly one coordinate (i.e. they are adjacent horizontally or vertically), and the bench assigned to a road must be one of the two valid odd-coordinate positions determined by its endpoints:

For a horizontal road connecting (x,y)(x, y) and (x+2,y)(x+2,y), the two candidate bench positions are (x+1,y+1)(x+1,y+1) and (x+1,y1)(x+1,y-1). For a vertical road connecting (x,y)(x,y) and (x,y+2)(x,y+2), the two candidate bench positions are (x+1,y+1)(x+1,y+1) and (x1,y+1)(x-1,y+1).

The bench positions chosen for different roads must be distinct.

sample

4
0 0
2 0
0 2
2 2
YES

3 0 1 1 1 1 3 3 1 0 2 -1 1

</p>