#P8520. Fountain Road and Bench Assignment
Fountain Road and Bench Assignment
Fountain Road and Bench Assignment
In a nearby park there are fountains, numbered to . Each fountain is represented as a point on the 2D plane where both and 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 , 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 where both and are odd, and benches must be at distinct locations. Moreover, a bench at 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 can only be assigned to one of the roads connecting and , and , and , or and .
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 (, for example), which is the number of fountains. Each of the following lines contains two even integers and , 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 on the next line representing the number of roads used (in any valid road network connecting all fountains, a spanning tree suffices, so if ). Then output lines, each containing five space‐separated integers: , , , . Here and are the indices of the two fountains connected by the road, and 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 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 and , the two candidate bench positions are and . For a vertical road connecting and , the two candidate bench positions are and .
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>