시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB133350.000%

문제

In the country of Optopia, they do everything as optimal as possible, and everything inside of Optopia has been designed with this in mind. For example, in order to guarantee that GPS route planners are always optimal, the road network of Optopia has been designed such that there is exactly one way to travel between any two cities in Optopia.

Optopia also has a network of bus lines, where each bus line travels back and forth between two cities, stopping at every city in between. Recently, there was a big scandal in Optopia. A citizen of Optopia figured out that the current network of bus lines is in fact non-optimal. It uses too many bus lines!

This is where you come into the story. You have been hired by Optopia to fix their embarrassing mistake. Your task is to design a new optimal network of bus lines. Optopia has specified two requirements for the new bus line network:

  • It must be possible to travel between any two pairs of cities by bus.
  • The number of bus lines should be as few as possible.

Model the country of Optopia as an undirected graph, where the nodes represent the cities of Optopia, and where the edges represent the roads between pairs of cities. Additionally, represent each bus line by two cities, the two end stops of that bus line.

입력

The first line consists of one integer $N$ ($3 \leq N \leq 2 \cdot 10^5$), the number of cities in Optopia. The next $N-1$ lines consists of two integers $u$ and $v$ ($1 \leq u,v \leq N$, $u \neq v$), a pair of cities that are connected by a road. It is guaranteed that Optopia is connected, meaning it is possible to travel between any two cities using the road network.

출력

On the first line output the optimal number of bus lines $M$. Then output $M$ lines, where the $i$-th line should contain two space separated integers $a_i, b_i$ ($1 \leq a_i, b_i \leq N$), the two endpoints of the $i$-th bus line.

예제 입력 1

3
1 2
2 3

예제 출력 1

1
1 3

예제 입력 2

5
1 2
1 3
1 4
1 5

예제 출력 2

2
2 4
3 5

출처

Contest > KTH Challenge > KTH Challenge 2022 F번

  • 문제를 만든 사람: Björn Martinsson