Problem:
Score : 1600 points

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.

Sample Input 1

3
1 2 3
1 2
2 3

Sample 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.

Sample Input 2

5
5 4 1 2 3
1 2
1 3
2 4
2 5

Sample Output 2

1 2

Sample Input 3

3
1 1 1
1 2
2 3

Sample Output 3

Note that the correct output may be an empty line.

Solution in Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

const INF: i64 = 1i64 << 50;

fn dfs(v: usize, p: Option<usize>, a: &[i64], dp: &mut [i64], edges: &[Vec<usize>]) {
    let mut inf = false;
    for &w in edges[v].iter() {
        if Some(w) == p {
            continue;
        }
        dfs(w, Some(v), a, dp, edges);
        if dp[w] < a[v] {
            inf = true;
        }
    }
    dp[v] = if inf { INF } else { a[v] };
}

fn solve(v: usize, a: &[i64], edges: &[Vec<usize>]) -> bool {
    let n = edges.len();
    let mut dp = vec![0; n];
    dfs(v, None, a, &mut dp, edges);
    dp[v] == INF
}

fn main() {
    let n = get();
    let mut edges = vec![Vec::new(); n];
    let a: Vec<_> = (0 .. n).map(|_| get()).collect();
    for _ in 0 .. n - 1 {
        let a = get::<usize>() - 1;
        let b = get::<usize>() - 1;
        edges[a].push(b);
        edges[b].push(a);
    }
    let mut ans = Vec::new();
    for i in 0 .. n {
        if solve(i, &a, &edges) {
            ans.push(i)
        }
    }
    for i in 0 .. ans.len() {
        print!("{}{}", ans[i] + 1, if i == ans.len() - 1 { "" } else { " " });
    }
    println!("");
}