Contingency Plan

시간 제한2초메모리 제한1024 MB

요약
트리가 주어질 때, 각 단계 x에서 앞선 x개의 간선을 제거해도 그래프가 연결되도록 기존 간선과 겹치지 않는 대체 간선 N-1개를 찾는 문제이다.
난이도

어려움10점 중 8점

유형
트리, 그래프, 그리디, DFS
정답자
아직 제출이 없습니다

문제

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 N−1N - 1 cables, numbered from 11 to N−1N - 1, that connect all the computers into a single network. Cable ii connects computer U_iU\_i and V_iV\_i.

Through your research, there are N−1N - 1 levels of disasters, numbered from 11 to N−1N - 1, that might happen in the future. In disaster level xx, all cables ii such that 1≤i≤x1 ≤ i ≤ 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 N−1N - 1 backup cables, numbered from 11 to N−1N - 1. If an existing cable ii is damaged, then backup cable ii will be deployed to connect computer A_iA\_i and B_iB\_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 (2≤N≤100,0002 ≤ N ≤ 100\\, 000) representing the number of computers. Each of the next N−1N - 1 lines contains 22 integers U_iU\_i V_iV\_i (1≤U_i,V_i≤N1 ≤ U\_i , V\_i ≤ 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 N−1N - 1 lines, representing your contingency plan that satisfies all the requirements. Each line contains 22 integers A_iA\_i B_iB\_i (1≤A_i,B_i≤N1 ≤ A\_i , B\_i ≤ 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 in a single line.

예제2

  1. 예제 1

    입력
    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
    
  2. 예제 2

    입력
    3
    1 2
    2 3
    
    예상 출력
    -1