#P6802. [CEOI 2020] 道路

[CEOI 2020] 道路

Description

The government of Treeland plans to build a brand-new road network. Treeland has a total of 2N2N cities. Currently, NN roads have already been built, and each road is a line segment connecting two cities. These NN roads do not intersect each other in pairs (including at endpoints). You now need to build another N1N-1 roads, such that:

  1. Each road is a line segment connecting two cities.
  2. Roads may intersect only at endpoints.
  3. For any two cities, it must be possible to travel between them using this road network.

Input Format

The first line contains an integer NN.

The next NN lines each contain four integers x1,y1,x2,y2x_1, y_1, x_2, y_2, indicating that there is a road directly connecting the two cities at (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2).

Output Format

Output N1N-1 lines.

Each line contains four integers x1,y1,x2,y2x_1, y_1, x_2, y_2, representing a newly built road connecting the two cities at (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2).

If there are multiple solutions, output any one.

5
1 3 3 6
5 1 5 3
3 3 6 5
2 1 4 1
2 3 4 2
2 1 1 3
2 3 2 1
3 3 2 3
5 1 4 2

Hint

Sample Explanation

In the figure below, solid lines are roads that have already been built, and dashed lines are new roads.

Subtasks

All testdata satisfy: 2N1052 \leq N \leq 10^5, 107x1,y1,x2,y2107-10^7 \leq x_1, y_1, x_2, y_2 \leq 10^7.

The constraints for each subtask are as follows:

Subtask ID Score Constraints
11 00 Sample
22 1515 All input segments are vertical
33 Any two input segments are parallel
44 All input segments are horizontal or vertical
55 N104N \leq 10^4
66 4040 No special constraints

Note that the actual scoring distribution in the judge is different from the agreement above.

Translated by ChatGPT 5