Expansion of the road network

시간 제한1.5초메모리 제한2048 MB

요약
연결된 무방향 그래프가 어떤 트리의 제곱인지 판별하고, 그렇다면 제곱이 주어진 그래프와 같은 트리를 복원한다.
난이도

어려움10점 중 8점

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

문제

Legend has it that, long ago, the Service of Braveway Connections (SBC) administered a network of bidirectional roads that connected various cities. At that time, the layout was extremely simple: between any two cities there was exactly one path.

With population growth and increased transportation of goods, the Institute of Connected and Planned Cities (ICPC) took control and decided to modernize the network. To avoid internal traffic in intermediate cities and speed up travel, new direct roads were built between certain pairs of cities. A new road was created between two cities AA and BB whenever, in the original layout, the path between them passed through exactly one intermediate city.

Today, we only have the current map of the network, and ICPC wants to find out whether it could indeed have arisen from this process.

Your task is to analyze the current map and determine whether the legend could be true. If possible, you should also reconstruct and print a possible original layout of the network.

입력

The first line contains two integers NN and MM (3≤N≤1053 ≤ N ≤ 10^5, 2≤M≤4×1052 ≤ M ≤ 4 \times 10^5), representing, respectively, the number of cities and the number of roads in the current map.

Each of the following MM lines contains two integers u_iu\_i and v_iv\_i (1≤u_i,v_i≤N1 ≤ u\_i , v\_i ≤ N, u_i≠v_iu\_i \ne v\_i), indicating that there is a bidirectional road between cities u_iu\_i and v_iv\_i. In the current map, it is guaranteed that there is a path between any pair of cities and that there is at most one road between any pair of cities.

출력

If the current map could have arisen from the process described in the legend, the output should contain N−1N −1 lines. Each line should contain two integers a_ia\_i and b_ib\_i (1≤a_i,b_i≤N1 ≤ a\_i , b\_i ≤ N, a_i≠b_ia\_i \ne b\_i), indicating that there was a direct road between cities a_ia\_i and b_ib\_i in the original layout.

Otherwise, the output should contain only one line with a single character “*” (asterisk).

If there is more than one possible original layout, print any of them.

예제2

  1. 예제 1

    입력
    3 3
    1 2
    3 2
    1 3
    
    예상 출력
    1 2
    1 3
    
  2. 예제 2

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