传统题 1000ms 256MiB

E - Unique Color

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

E - Unique Color

Score : $500$ points

Problem Statement

Given is a tree with $N$ vertices numbered $1$ through $N$. The $i$-th edge connects Vertex $A_i$ and Vertex $B_i$. Vertex $i$ is painted in color $C_i$ (in this problem, colors are represented as integers).

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

Find all good vertices.

Constraints

  • $2 \leq N \leq 10^5$
  • $1 \leq C_i \leq 10^5$
  • $1 \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 $1$ to Vertex $6$ contains Vertices $1,2,3,6$. Among them, only Vertex $6$ itself is painted in the same color as Vertex $6$, so it is a good vertex.
On the other hand, the shortest path from Vertex $1$ to Vertex $5$ contains Vertices $1,2,5$, and Vertex $1$ is painted in the same color as Vertex $5$, so Vertex $5$ 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

2024寒假入门组刷题营(十五)

未参加
状态
已结束
规则
ACM/ICPC
题目
9
开始于
2024-2-15 13:30
结束于
2024-2-15 15:30
持续时间
2 小时
主持人
参赛人数
10