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)

use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;
fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let num: Vec<i64> = (0..n).map(|_| sc.ne()).collect();
    let mut adj = vec![Vec::new(); n];

    for _ in 0..n - 1 {
        let u = sc.ne::<usize>() - 1;
        let v = sc.ne::<usize>() - 1;
        // 自分より大きいのに動かしたら負け
        if num[u] > num[v] {
            adj[u].push(v);
        }
        if num[v] > num[u] {
            adj[v].push(u);
        }
    }
    fn dfs(cur: usize, adj: &Vec<Vec<usize>>) -> bool {
        let mut res = false;
        for &nxt in &adj[cur] {
            if dfs(nxt, &adj) == false {
                res = true;
            }
        }
        res
    }
    for i in 0..n {
        if dfs(i, &adj) {
            print!("{} ", i + 1);
        }
    }
    println!("");
}
const DEFAULT_STACK: usize = 16 * 1024 * 1024;
fn main() {
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => return None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => panic!("parse error"),
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}