Scanf.scanf "%d" (fun n ->
    let nei = Array.make n [] in
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    for i = 1 to n - 1 do
        Scanf.scanf " %d %d" (fun a b ->
            let a = a - 1 in let b = b - 1 in nei.(a) <- b :: nei.(a);
            nei.(b) <- a :: nei.(b);
        )
    done;

    let module S = Set.Make (struct type t = int let compare = compare end) in

    let mex set =
        let rec loop i =
            if S.mem i set then loop (i + 1) else i
        in
        loop 0
    in

    let rec grundy =
        let hash = Hashtbl.create 1 in
        fun ((arr, pos) as key) ->
            if Hashtbl.mem hash key then Hashtbl.find hash key else
                let calc () =
                    if arr.(pos) = 0 then 0 else
                        let arr2 = Array.copy arr in
                        let () = arr2.(pos) <- arr2.(pos) - 1 in
                        let set = List.fold_left (fun set v -> S.add (grundy (arr2, v)) set) S.empty nei.(pos) in
                        mex set
                in
                let r = calc () in
                let () = Hashtbl.add hash key r in
                r
    in
    for i = 0 to n - 1 do
        if grundy (a, i) <> 0 then Printf.printf "%d " (i + 1)
    done;
    print_newline ()
)