import Data.Graph.Inductive.Graph
import Data.Graph.Inductive.PatriciaTree
import Control.Monad
import Data.Maybe
import Data.Vector.Unboxed (Vector)
import qualified Data.Vector.Unboxed as V

main = do
  n <- readLn
  as <- map read.words <$> getLine
  edges <- replicateM (n-1) $ (\[a,b]->(a,b)).map read.words <$> getLine
  let
    avec = V.fromList as
    tree = mkUGraph [1..n] edges :: Gr () ()
  putStr $ unwords $ map show $ solve n tree avec

inf = 1000000001
solve :: Int -> Gr () () -> 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 = foldl f True childs
    f acc child
      | child == visited = acc
      | otherwise = acc && a <= go node child
    childs = neighbors tree node
