n = int(input())
tree = [set() for i in range(n)]
con = [0]*n
ans = [0]*n
scr = 0
for _ in range(n-1):
  a,b = map(lambda x:int(x)-1, input().split())
  tree[a].add(b)
  tree[b].add(a)
  con[a] += 1
  con[b] += 1
st = []
for i in range(n):
  if con[i] == 1:
    st.append(i)
c = list(map(int, input().split()))
c.sort(reverse=True)
while st:
  v = st.pop()
  if ans[v]:
    continue
  ans[v] = c.pop()
  scr += ans[v]*con[v]
  con[v] = 0
  for x in tree[v]:
    if ans[x]:
      continue
    con[x] -= 1
    if con[x] <= 1:
      st.append(x)
print(scr)
print(" ".join(map(str,ans))) n = int(input()) n int(input()) int input() input set() for i in range(n) for i in range(n) i range(n) range n for i in range(n) set() set tree = [set() for i in range(n)] tree [set() for i in range(n)] con = [0]*n con [0]*n [0] 0 n ans = [0]*n ans [0]*n [0] 0 n scr = 0 scr 0 for _ in range(n-1):
  a,b = map(lambda x:int(x)-1, input().split())
  tree[a].add(b)
  tree[b].add(a)
  con[a] += 1
  con[b] += 1 _ range(n-1) range n-1 n 1 a,b = map(lambda x:int(x)-1, input().split()) a map(lambda x:int(x)-1, input().split()) map lambda x:int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split b tree[a].add(b) [a].add [a] tree a add b tree[b].add(a) [b].add [b] tree b add a con[a] += 1 con[a] con a 1 con[b] += 1 con[b] con b 1 st = [] st [] for i in range(n):
  if con[i] == 1:
    st.append(i) i range(n) range n if con[i] == 1:
    st.append(i) con[i] == 1 con[i] con i 1 st.append(i) st.append st append i c = list(map(int, input().split())) c list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c.sort(reverse=True) c.sort c sort reverse=True reverse True while st:
  v = st.pop()
  if ans[v]:
    continue
  ans[v] = c.pop()
  scr += ans[v]*con[v]
  con[v] = 0
  for x in tree[v]:
    if ans[x]:
      continue
    con[x] -= 1
    if con[x] <= 1:
      st.append(x) st v = st.pop() v st.pop() st.pop st pop if ans[v]:
    continue
   ans[v] ans v continue ans[v] = c.pop() ans[v] ans v c.pop() c.pop c pop scr += ans[v]*con[v] scr ans[v]*con[v] ans[v] ans v con[v] con v con[v] = 0 con[v] con v 0 for x in tree[v]:
    if ans[x]:
      continue
    con[x] -= 1
    if con[x] <= 1:
      st.append(x) x tree[v] tree v if ans[x]:
      continue
     ans[x] ans x continue con[x] -= 1 con[x] con x 1 if con[x] <= 1:
      st.append(x) con[x] <= 1 con[x] con x 1 st.append(x) st.append st append x print(scr) print scr print(" ".join(map(str,ans))) print " ".join(map(str,ans)) " ".join " " join map(str,ans) map str ans con = [0]*n [0]*n con a,b = map(lambda x:int(x)-1, input().split()) map(lambda x:int(x)-1, input().split()) a tree = [set() for i in range(n)] [set() for i in range(n)] tree ans = [0]*n [0]*n ans scr += ans[v]*con[v] ans[v]*con[v] scr n = int(input()) int(input()) n c = list(map(int, input().split())) list(map(int, input().split())) c scr = 0 0 scr st = [] [] st v = st.pop() st.pop() v b = map(lambda x:int(x)-1, input().split()) map(lambda x:int(x)-1, input().split()) b
n = int(input())
tree = [set() for i in range(n)]
con = [0]*n
ans = [0]*n
scr = 0
for _ in range(n-1):
  a,b = map(lambda x:int(x)-1, input().split())
  tree[a].add(b)
  tree[b].add(a)
  con[a] += 1
  con[b] += 1
st = []
for i in range(n):
  if con[i] == 1:
    st.append(i)
c = list(map(int, input().split()))
c.sort(reverse=True)
while st:
  v = st.pop()
  if ans[v]:
    continue
  ans[v] = c.pop()
  scr += ans[v]*con[v]
  con[v] = 0
  for x in tree[v]:
    if ans[x]:
      continue
    con[x] -= 1
    if con[x] <= 1:
      st.append(x)
print(scr)
print(" ".join(map(str,ans)))