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,Q,l,i=sorted(list(map(int,input().split())))[::-1],[0],[0]*n,0
print(sum(c[1:]))
while Q:
 a=Q.pop()
 if l[a]!=0:continue
 l[a]=c[i];i+=1
 for j in e[a]:Q.append(j)
print(*l) 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 c,Q,l,i=sorted(list(map(int,input().split())))[::-1],[0],[0]*n,0 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 Q [0] 0 l [0]*n [0] 0 n i 0 print(sum(c[1:])) print sum(c[1:]) sum c[1:] c 1: 1 while Q:
 a=Q.pop()
 if l[a]!=0:continue
 l[a]=c[i];i+=1
 for j in e[a]:Q.append(j) Q a=Q.pop() a Q.pop() Q.pop Q pop if l[a]!=0:continue
  l[a]!=0 l[a] l a 0 l[a]=c[i] l[a] l a c[i] c i i+=1 i 1 for j in e[a]:Q.append(j j e[a] e a print(*l) print *l l n=int(input()) int(input()) n e=[[]for i in range(n)] [[]for i in range(n)] e i+=1 1 i c,Q,l,i=sorted(list(map(int,input().split())))[::-1],[0],[0]*n,0 sorted(list(map(int,input().split())))[::-1] c a=Q.pop() Q.pop() a l,i=sorted(list(map(int,input().split())))[::-1],[0],[0]*n,0 [0]*n l i=sorted(list(map(int,input().split())))[::-1],[0],[0]*n,0 0 i Q,l,i=sorted(list(map(int,input().split())))[::-1],[0],[0]*n,0 [0] Q
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,Q,l,i=sorted(list(map(int,input().split())))[::-1],[0],[0]*n,0
print(sum(c[1:]))
while Q:
 a=Q.pop()
 if l[a]!=0:continue
 l[a]=c[i];i+=1
 for j in e[a]:Q.append(j)
print(*l)