AtCoder Grand Contest 010
F
Tree Game
AtCoder
⌀ 2897
原题
← E→
翻译中…

Problem Statement

翻译中…

There is a tree with $N$ vertices, numbered $1$ through $N$. The $i$-th of the $N-1$ edges connects vertices $a_i$ and $b_i$.

翻译中…

Currently, there are $A_i$ stones placed on vertex $i$. Takahashi and Aoki will play a game using this tree.

翻译中…

First, Takahashi will select a vertex and place a piece on it. Then, starting from Takahashi, they will alternately perform the following operation:

翻译中…
  • Remove one stone from the vertex currently occupied by the piece.
  • Then, move the piece to a vertex that is adjacent to the currently occupied vertex.
翻译中…

The player who is left with no stone on the vertex occupied by the piece and thus cannot perform the operation, loses the game. Find all the vertices $v$ such that Takahashi can place the piece on $v$ at the beginning and win the game.

翻译中…

Constraints

翻译中…
  • $2 ≦ N ≦ 3000$
  • $1 ≦ a_i,b_i ≦ N$
  • $0 ≦ A_i ≦ 10^9$
  • The given graph is a tree.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 … A_N
a_1 b_1
:
a_{N-1} b_{N-1}

翻译中…

Output

翻译中…

Print the indices of the vertices $v$ such that Takahashi can place the piece on $v$ at the beginning and win the game, in a line, in ascending order.

翻译中…

样例

Input #1
3
1 2 3
1 2
2 3
Output #1
2
The following is one possible progress of the game when Takahashi places the piece on vertex $2$: - Takahashi moves the piece to vertex $1$. The number of the stones on each vertex is now: $(1,1,3)$. - Aoki moves the piece to vertex $2$. The number of the stones on each vertex is now: $(0,1,3)$. - Takahashi moves the piece to vertex $1$. The number of the stones on each vertex is now: $(0,0,3)$. - Aoki cannot take a stone from the vertex, and thus Takahashi wins.
Input #2
5
5 4 1 2 3
1 2
1 3
2 4
2 5
Output #2
1 2
Input #3
3
1 1 1
1 2
2 3
Output #3

Note that the correct output may be an empty line.
题目信息
题号
agc010_f
时间限制
2 s
内存限制
256 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。