import Data.Graph.Inductive.Graph
import Data.Graph.Inductive.PatriciaTree
import Control.Monad
import Data.Maybe

main = do
  n <- readLn
  as <- map read.words <$> getLine :: IO [Int]
  edges <- replicateM (n-1) $ (\[a,b]->(a,b,())).map read.words <$> getLine :: IO [LEdge ()]
  let tree = mkGraph (zip [1..n] as) edges :: Gr Int ()
  putStr $ unwords $ map show $ solve n tree

inf = 1000000001
solve :: Int -> Gr Int () -> [Int]
solve n tree = filter inner [1..n]
  where
  inner k = go 0 k == inf
  go visited k
    | all (>=a) as = a
    | otherwise = inf
    where
    a = fromJust $ lab tree k
    as = map (go k) childs
    childs = filter (/=visited) (neighbors tree k)