atcoder#ABC198E. [ABC198E] Unique Color
[ABC198E] Unique Color
Score : points
Problem Statement
Given is a tree with vertices numbered through . The -th edge connects Vertex and Vertex . Vertex is painted in color (in this problem, colors are represented as integers).
Vertex is said to be good when the shortest path from Vertex to Vertex does not contain a vertex painted in the same color as Vertex , except Vertex itself.
Find all good vertices.
Constraints
- The given graph is a tree.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print all good vertices as integers, in ascending order, using newline as a separator.
6
2 7 1 8 2 8
1 2
3 6
3 2
4 3
2 5
1
2
3
4
6
For example, the shortest path from Vertex to Vertex contains Vertices . Among them, only Vertex itself is painted in the same color as Vertex , so it is a good vertex. On the other hand, the shortest path from Vertex to Vertex contains Vertices , and Vertex is painted in the same color as Vertex , so Vertex is not a good vertex.
10
3 1 4 1 5 9 2 6 5 3
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
1
2
3
5
6
7
8