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

문제

Every year at Easter Bob's grandmother organizes The Great Egg Hunt in their family mansion. This has been a family tradition since even before Bob was born. Bob's grandmother starts by filling up a giant Easter Egg with candy. She then picks a room (uniformly) at random and hides the egg there. First person to find the egg gets to keep all the candy inside.

Bob's family mansion consists of $N$ rooms. There are $N-1$ doorways between pairs of rooms. You can assume that the mansion is connected, meaning it is always possible to walk from any room to any other room using the doorways.

As Bob is a veteran egg hunter, Bob has developed a method for finding the egg, which he calls Egg First Search:

  1. If Bob is currently in an unexplored room, then he searches that room. Since Bob is a veteran egg hunter, if the egg is in that room, then he will find it.
  2. Otherwise, Bob moves to an adjacent room that is in the direction of any of the closest unexplored rooms. If there are multiple rooms he could move to, then he picks one (uniformly) at random.

Assume it takes $1$ unit of time for Bob to search a room, and also assume that it takes $1$ unit of time for Bob to move from a room to an adjacent room.

The one thing Bob is still not sure about is in which room he should start his search. So he asks you for help. Given a map of the mansion, find which starting room(s) that minimize the expected time to find the egg using Bob's Egg First Search method.

입력

The first line consists of one integer $N$ ($1 \leq N \leq 2 \cdot 10^5$), the number of rooms in the mansion. The next $N-1$ lines consist of two space separated integers $u$ and $v$ ($1 \leq u,v \leq N$, $u \neq v$), a pair of rooms that are connected by a doorway. It is guaranteed that the mansion is connected, meaning it is always possible to walk from any room to any other room using the doorways.

출력

On the first line print an integer $M$, the number of optimal starting rooms. On the second line, print $M$ space separated integers $S_1, \ldots, S_M$ ($1 \leq S_1 < S_2 < \ldots < S_M \leq N$), the list of optimal starting rooms.

예제 입력 1

3
1 2
2 3

예제 출력 1

2
1 3

예제 입력 2

5
1 2
1 3
1 4
1 5

예제 출력 2

4
2 3 4 5

출처

Contest > KTH Challenge > KTH Challenge 2022 G번

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