atcoder#ABC303E. [ABC303E] A Gift From the Stars
[ABC303E] A Gift From the Stars
Score : points
Problem Statement
A graph with vertices and edges is called a level- star if and only if:
- it has a vertex that is connected to each of the other vertices with an edge, and there are no other edges.
At first, Takahashi had a graph consisting of stars. He repeated the following operation until every pair of vertices in the graph was connected:
- choose two vertices in the graph. Here, the vertices must be disconnected, and their degrees must be both . Add an edge that connects the chosen two vertices.
He then arbitrarily assigned an integer from through to each of the vertices in the graph after the procedure. The resulting graph is a tree; we call it . has edges, the -th of which connects and .
Takahashi has now forgotten the number and levels of the stars that he initially had. Find them, given .
Constraints
- The given graph is an -vertex tree obtained by the procedure in the problem statement.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Suppose that Takahashi initially had stars, whose levels were . Sort in ascending order, and print them with spaces in between.
We can prove that the solution is unique in this problem.
6
1 2
2 3
3 4
4 5
5 6
2 2
Two level- stars yield , as the following figure shows:
9
3 9
7 8
8 6
4 6
4 1
5 9
7 3
5 2
2 2 2
20
8 3
8 18
2 19
8 20
9 17
19 7
8 7
14 12
2 15
14 10
2 13
2 16
2 1
9 5
10 15
14 6
2 4
2 11
5 12
2 3 4 7