Contingency Plan
시간 제한2초메모리 제한1024 MB
트리가 주어질 때, 각 단계 x에서 앞선 x개의 간선을 제거해도 그래프가 연결되도록 기존 간선과 겹치지 않는 대체 간선 N-1개를 찾는 문제이다.
문제
You are working as a manager in The ICPC Company. In the company building, there are computers, numbered from to . There are cables, numbered from to , that connect all the computers into a single network. Cable connects computer and .
Through your research, there are levels of disasters, numbered from to , that might happen in the future. In disaster level , all cables such that 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 backup cables, numbered from to . If an existing cable is damaged, then backup cable will be deployed to connect computer and . If an existing cable is not damaged, then backup cable 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 and exists, then there should not be any backup cable that connects computers and 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 () representing the number of computers. Each of the next lines contains integers () representing cable . All the cables connect all the computers into a single network.
출력
If a contingency plan is possible to create, then the output consists of lines, representing your contingency plan that satisfies all the requirements. Each line contains integers () representing backup cable . If several contingency plans exist, output any of them.
If a contingency plan is impossible to create, then output -1 in a single line.