import Control.Monad
import Data.Maybe
import Data.Vector.Unboxed (Vector)
import qualified Data.Vector.Unboxed as V
import Data.IntMap (IntMap,(!))
import qualified Data.IntMap as IM

main = do
  n <- readLn
  as <- map read.words <$> getLine
  edges <- replicateM (n-1) $ map read.words <$> getLine
  let
    avec = V.fromList as
    tree = foldr f zeroMap edges
    zeroMap = IM.fromDistinctAscList $ zip [1..n] $ repeat []
    f [a,b] tree = IM.adjust (a:) b $ IM.adjust (b:) a  tree
  putStr $ unwords $ map show $ solve n tree avec

inf = 1000000001
solve :: Int -> IntMap [Int] -> Vector Int -> [Int]
solve n tree avec = filter inner [1..n]
  where
  inner node = go 0 node == inf
  go visited node
    | lose = a
    | otherwise = inf
    where
    a = V.unsafeIndex avec (node-1)
    lose = foldr f True childs
    f child acc
      | child == visited = acc
      | otherwise = acc && a <= go node child
    childs = tree!node