d = gets.chomp!.to_i
node = {}
counter = {}

require 'pp'
require 'set'

(d - 1).times do |i|
    a, b = gets.chomp!.split(" ").map(&:to_i)
    counter[a] = (counter[a] || 0) + 1
    counter[b] = (counter[b] || 0) + 1
end
c = gets.chomp!.split(" ").map(&:to_i)

pp c

pp counter

x = counter.sort {|(_, v1), (_, v2)| v2 <=> v1 }

pp x

puts x.map {|index, count|
    c[index - 1]
}.join(" ")
