#ABC198E. [ABC198E] Unique Color

[ABC198E] Unique Color

Score : 500500 points

Problem Statement

Given is a tree with NN vertices numbered 11 through NN. The ii-th edge connects Vertex AiA_i and Vertex BiB_i. Vertex ii is painted in color CiC_i (in this problem, colors are represented as integers).

Vertex xx is said to be good when the shortest path from Vertex 11 to Vertex xx does not contain a vertex painted in the same color as Vertex xx, except Vertex xx itself.

Find all good vertices.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1Ci1051 \leq C_i \leq 10^5
  • 1Ai,BiN1 \leq A_i,B_i \leq N
  • The given graph is a tree.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

C1C_1 \ldots CNC_N

A1A_1 B1B_1

\vdots

AN1A_{N-1} BN1B_{N-1}

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 11 to Vertex 66 contains Vertices 1,2,3,61,2,3,6. Among them, only Vertex 66 itself is painted in the same color as Vertex 66, so it is a good vertex. On the other hand, the shortest path from Vertex 11 to Vertex 55 contains Vertices 1,2,51,2,5, and Vertex 11 is painted in the same color as Vertex 55, so Vertex 55 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