#P8921. 『MdOI R5』Triangulation

    ID: 9573 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>洛谷原创Special JudgeO2优化洛谷月赛

『MdOI R5』Triangulation

Problem Description

There is a regular nn-gon whose vertices are labeled 11 to nn in clockwise order. You are given n3n - 3 distinct diagonals of this polygon, and they satisfy that they can only intersect at vertices. In this way, we obtain an undirected graph with nn vertices and 2n32n - 3 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 nn-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 nn.

The next n3n - 3 lines each contain two integers u,vu, v, representing a given diagonal (u,v)(u, v).

Output Format

If there is no solution, output one line with the integer 1-1.

If there is a solution, output n1n - 1 lines, each containing two integers u,vu, v, representing an edge (u,v)(u, v) 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 100%100\% of the testdata, 3n3×1053 \le n \le 3 \times 10^5.

Subtask1(9%)\operatorname{Subtask} 1(9\%): n10n \le 10.

Subtask2(1%)\operatorname{Subtask} 2(1\%): nn is odd.

Subtask3(10%)\operatorname{Subtask} 3(10\%): u=1u = 1.

Subtask4(30%)\operatorname{Subtask} 4(30\%): n100n \le 100.

Subtask5(30%)\operatorname{Subtask} 5(30\%): n5×103n \le 5 \times 10^3.

Subtask6(20%)\operatorname{Subtask} 6(20\%): no special constraints.

Translated by ChatGPT 5