# スタート地点からDFSで大きい順に入れていけば、最も大きい数以外は得点を得られる

N = int(input())
E = [[] for i in range(N)]
for i in range(N-1):
  a,b = map(int,input().split())
  E[a-1].append(b-1)
  E[b-1].append(a-1)

# 得点を大きい順に並べる
C = sorted(list(map(int,input().split())))[::-1]

ans = [-1 for i in range(N)] # -1は未訪問
point = sum(C[1:])

from collections import deque
q = deque([])
q.append(0)
ind = 0
while q:
  v = q.popleft()
  if ans[v] != -1:
    # 訪問済み
    continue
  ans[v] = C[ind]
  ind += 1
  if ind == len(C):
    break
  children = E[v]
  for child in children:
    q.append(child)
  
print(point)  
print(*ans) N = int(input()) N int(input()) int input() input [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] E = [[] for i in range(N)] E [[] for i in range(N)] for i in range(N-1):
  a,b = map(int,input().split())
  E[a-1].append(b-1)
  E[b-1].append(a-1)

# 得点を大きい順に並べる i range(N-1) range N-1 N 1 a,b = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b E[a-1].append(b-1) [a-1].append [a-1] E a-1 a 1 append b-1 b 1 E[b-1].append(a-1) [b-1].append [b-1] E b-1 b 1 append a-1 a 1 C = sorted(list(map(int,input().split())))[::-1] C sorted(list(map(int,input().split())))[::-1] (list(map(int,input().split()))) sorted list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ::-1 -1 -1 for i in range(N) for i in range(N) i range(N) range N for i in range(N) -1 ans = [-1 for i in range(N)] ans [-1 for i in range(N)] point = sum(C[1:]) point sum(C[1:]) sum C[1:] C 1: 1 from collections import deque q = deque([]) q deque([]) deque [] q.append(0) q.append q append 0 ind = 0 ind 0 while q:
  v = q.popleft()
  if ans[v] != -1:
    # 訪問済み
    continue
  ans[v] = C[ind]
  ind += 1
  if ind == len(C):
    break
  children = E[v]
  for child in children:
    q.append(child)
   q v = q.popleft() v q.popleft() q.popleft q popleft if ans[v] != -1:
    # 訪問済み
    continue
   ans[v] != -1 ans[v] ans v -1 continue ans[v] = C[ind] ans[v] ans v C[ind] C ind ind += 1 ind 1 if ind == len(C):
    break
   ind == len(C) ind len(C) len C break children = E[v] children E[v] E v for child in children:
    q.append(child)
   child children q.append(child) q.append q append child print(point) print point print(*ans) print *ans ans q = deque([]) deque([]) q a,b = map(int,input().split()) map(int,input().split()) a ans = [-1 for i in range(N)] [-1 for i in range(N)] ans point = sum(C[1:]) sum(C[1:]) point ind = 0 0 ind v = q.popleft() q.popleft() v C = sorted(list(map(int,input().split())))[::-1] sorted(list(map(int,input().split())))[::-1] C ind += 1 1 ind N = int(input()) int(input()) N E = [[] for i in range(N)] [[] for i in range(N)] E b = map(int,input().split()) map(int,input().split()) b children = E[v] E[v] children
# スタート地点からDFSで大きい順に入れていけば、最も大きい数以外は得点を得られる

N = int(input())
E = [[] for i in range(N)]
for i in range(N-1):
  a,b = map(int,input().split())
  E[a-1].append(b-1)
  E[b-1].append(a-1)

# 得点を大きい順に並べる
C = sorted(list(map(int,input().split())))[::-1]

ans = [-1 for i in range(N)] # -1は未訪問
point = sum(C[1:])

from collections import deque
q = deque([])
q.append(0)
ind = 0
while q:
  v = q.popleft()
  if ans[v] != -1:
    # 訪問済み
    continue
  ans[v] = C[ind]
  ind += 1
  if ind == len(C):
    break
  children = E[v]
  for child in children:
    q.append(child)
  
print(point)  
print(*ans)