#P15624. [ICPC 2022 Jakarta R] Contingency Plan

[ICPC 2022 Jakarta R] Contingency Plan

题目描述

You are working as a manager in The ICPC Company. In the company building, there are NN computers, numbered from 11 to NN. There are N1N - 1 cables, numbered from 11 to N1N - 1, that connect all the computers into a single network. Cable ii connects computer UiU_i and ViV_i.

Through your research, there are N1N - 1 levels of disasters, numbered from 11 to N1N - 1, that might happen in the future. In disaster level xx, all cables ii such that 1ix1 \leq i \leq x are damaged. Damaged cables cannot be used for a connection.

As a manager, you want to create a contingency plan. In your contingency plan, there should be N1N - 1 backup cables, numbered from 11 to N1N - 1. If an existing cable ii is damaged, then backup cable ii will be deployed to connect computer AiA_i and BiB_i. If an existing cable ii is not damaged, then backup cable ii is not deployed and is not used for a connection.

For each disaster level, the backup cables, together with the undamaged cables, must keep all the computers connected in a single network. Furthermore, for practical reasons, if a cable that connects computers uu and vv exists, then there should not be any backup cable that connects computers uu and vv in your contingency plan.

Create a contingency plan that satisfies all the requirements, or determine if such a plan is impossible to create. If several contingency plans exist, choose any of them.

输入格式

Input begins with an integer NN (2N1000002 \leq N \leq 100\,000) representing the number of computers. Each of the next N1N - 1 lines contains 22 integers UiU_i ViV_i (1Ui,ViN1 \leq U_i, V_i \leq N) representing cable ii. All the cables connect all the computers into a single network.

输出格式

If a contingency plan is possible to create, then the output consists of N1N - 1 lines, representing your contingency plan that satisfies all the requirements. Each line contains 22 integers AiA_i BiB_i (1Ai,BiN1 \leq A_i, B_i \leq N) representing backup cable ii. If several contingency plans exist, output any of them.

If a contingency plan is impossible to create, then output 1-1 in a single line.

7
1 2
3 7
2 4
2 5
1 3
3 6
3 5
6 7
4 6
2 3
1 7
3 4
3
1 2
2 3
-1

提示

Explanation for the sample input/output #1

The following is an illustration for this sample. The circles represent the computers, while the black line and red dashed lines represent existing cables and backup cables, respectively. Damaged cables are not shown in the illustration.

:::align{center} :::

Explanation for the sample input/output #2

There should be 22 backup cables in the contingency plan. You can only have 11 backup cable, which will connect computers 11 and 33. The remaining pairs are already connected by the current cables.