#P8921. 『MdOI R5』Triangulation
『MdOI R5』Triangulation
Problem Description
There is a regular -gon whose vertices are labeled to in clockwise order. You are given distinct diagonals of this polygon, and they satisfy that they can only intersect at vertices. In this way, we obtain an undirected graph with vertices and edges.
A diagonal of a convex polygon is a line segment connecting two vertices that are different and not adjacent on the polygon.
In fact, this undirected graph can be any triangulation graph of a convex -gon.
You need to construct a spanning tree of this undirected graph such that the degree of every vertex is odd, or report that there is no solution.
Input Format
The first line contains an integer .
The next lines each contain two integers , representing a given diagonal .
Output Format
If there is no solution, output one line with the integer .
If there is a solution, output lines, each containing two integers , representing an edge in the spanning tree you constructed.
5
1 3
1 4
-1
8
6 8
5 8
2 4
2 5
1 5
3 2
2 4
7 8
6 8
2 1
1 5
8 1
Hint
For of the testdata, .
: .
: is odd.
: .
: .
: .
: no special constraints.
Translated by ChatGPT 5