import sys
import resource

sys.setrecursionlimit(20000)
n=int(input())
edges=[list(map(int,input().split())) for i in range(n-1)]
e = [[] for i in range(n)]
for a,b in edges:
  a-=1;b-=1
  e[a].append(b);e[b].append(a)
c=sorted(list(map(int,input().split())))
print(sum(c[:-1]))
visited=[False for i in range(n)]
node=[0]*n
cnt=0
def dfs(pos):
  global cnt,node,c
  if visited[pos]:return
  visited[pos]=True
  for p in e[pos]:
    dfs(p)
  node[pos]=c[cnt]
  cnt+=1
dfs(0)
print(' '.join(map(str,node))) import sys sys import resource resource sys.setrecursionlimit(20000) sys.setrecursionlimit sys setrecursionlimit 20000 n=int(input()) n int(input()) int input() input list(map(int,input().split())) for i in range(n-1) for i in range(n-1) i range(n-1) range n-1 n 1 for i in range(n-1) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split edges=[list(map(int,input().split())) for i in range(n-1)] edges [list(map(int,input().split())) for i in range(n-1)] [] 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 a,b in edges:
  a-=1;b-=1
  e[a].append(b);e[b].append(a) a b edges a-=1 a 1 b-=1 b 1 e[a].append(b) [a].append [a] e a append b e[b].append(a) [b].append [b] e b append a c=sorted(list(map(int,input().split()))) c sorted(list(map(int,input().split()))) sorted list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split print(sum(c[:-1])) print sum(c[:-1]) sum c[:-1] c :-1 -1 False for i in range(n) for i in range(n) i range(n) range n for i in range(n) False visited=[False for i in range(n)] visited [False for i in range(n)] node=[0]*n node [0]*n [0] 0 n cnt=0 cnt 0 def dfs(pos):
  global cnt,node,c
  if visited[pos]:return
  visited[pos]=True
  for p in e[pos]:
    dfs(p)
  node[pos]=c[cnt]
  cnt+=1 dfs global cnt,node,c if visited[pos]:return
   visited[pos] visited pos visited[pos]=True visited[pos] visited pos True for p in e[pos]:
    dfs(p)
   p e[pos] e pos dfs(p) dfs p node[pos]=c[cnt] node[pos] node pos c[cnt] c cnt cnt+=1 cnt 1 pos pos dfs(0) dfs 0 print(' '.join(map(str,node))) print ' '.join(map(str,node)) ' '.join ' ' join map(str,node) map str node n=int(input()) int(input()) n c=sorted(list(map(int,input().split()))) sorted(list(map(int,input().split()))) c def dfs(pos):
  global cnt,node,c
  if visited[pos]:return
  visited[pos]=True
  for p in e[pos]:
    dfs(p)
  node[pos]=c[cnt]
  cnt+=1 def dfs(pos):
  global cnt,node,c
  if visited[pos]:return
  visited[pos]=True
  for p in e[pos]:
    dfs(p)
  node[pos]=c[cnt]
  cnt+=1 dfs visited=[False for i in range(n)] [False for i in range(n)] visited node=[0]*n [0]*n node a-=1 1 a b-=1 1 b edges=[list(map(int,input().split())) for i in range(n-1)] [list(map(int,input().split())) for i in range(n-1)] edges e = [[] for i in range(n)] [[] for i in range(n)] e cnt=0 0 cnt
import sys
import resource

sys.setrecursionlimit(20000)
n=int(input())
edges=[list(map(int,input().split())) for i in range(n-1)]
e = [[] for i in range(n)]
for a,b in edges:
  a-=1;b-=1
  e[a].append(b);e[b].append(a)
c=sorted(list(map(int,input().split())))
print(sum(c[:-1]))
visited=[False for i in range(n)]
node=[0]*n
cnt=0
def dfs(pos):
  global cnt,node,c
  if visited[pos]:return
  visited[pos]=True
  for p in e[pos]:
    dfs(p)
  node[pos]=c[cnt]
  cnt+=1
dfs(0)
print(' '.join(map(str,node)))