N=int(input())
E=[[] for _ in range(N)]
for _ in range(N-1):
    a,b=map(lambda x:int(x)-1, input().split())
    E[a].append(b)
    E[b].append(a)
C=list(map(int, input().split()))

C.sort(reverse=True)

ans=[0]*(N)
stack=[0]
ans[0]=C[0]
k=1
while stack:
    n=stack.pop()
    for to in E[n]:
        if ans[to]!=0: continue
        ans[to]=C[k]
        k+=1
        stack.append(to)

print(sum(C[1:]))
print(' '.join(map(str,ans))) N=int(input()) N int(input()) int input() input [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] E=[[] for _ in range(N)] E [[] for _ in range(N)] for _ in range(N-1):
    a,b=map(lambda x:int(x)-1, input().split())
    E[a].append(b)
    E[b].append(a) _ 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 E[a].append(b) [a].append [a] E a append b E[b].append(a) [b].append [b] E b append a 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 ans=[0]*(N) ans [0]*(N) [0] 0 N stack=[0] stack [0] 0 ans[0]=C[0] ans[0] ans 0 C[0] C 0 k=1 k 1 while stack:
    n=stack.pop()
    for to in E[n]:
        if ans[to]!=0: continue
        ans[to]=C[k]
        k+=1
        stack.append(to) stack n=stack.pop() n stack.pop() stack.pop stack pop for to in E[n]:
        if ans[to]!=0: continue
        ans[to]=C[k]
        k+=1
        stack.append(to) to E[n] E n if ans[to]!=0: continue
         ans[to]!=0 ans[to] ans to 0 ans[to]=C[k] ans[to] ans to C[k] C k k+=1 k 1 stack.append(to) stack.append stack append to print(sum(C[1:])) print sum(C[1:]) sum C[1:] C 1: 1 print(' '.join(map(str,ans))) print ' '.join(map(str,ans)) ' '.join ' ' join map(str,ans) map str ans n=stack.pop() stack.pop() n N=int(input()) int(input()) N E=[[] for _ in range(N)] [[] for _ in range(N)] E k=1 1 k k+=1 1 k b=map(lambda x:int(x)-1, input().split()) map(lambda x:int(x)-1, input().split()) b a,b=map(lambda x:int(x)-1, input().split()) map(lambda x:int(x)-1, input().split()) a stack=[0] [0] stack C=list(map(int, input().split())) list(map(int, input().split())) C ans=[0]*(N) [0]*(N) ans
N=int(input())
E=[[] for _ in range(N)]
for _ in range(N-1):
    a,b=map(lambda x:int(x)-1, input().split())
    E[a].append(b)
    E[b].append(a)
C=list(map(int, input().split()))

C.sort(reverse=True)

ans=[0]*(N)
stack=[0]
ans[0]=C[0]
k=1
while stack:
    n=stack.pop()
    for to in E[n]:
        if ans[to]!=0: continue
        ans[to]=C[k]
        k+=1
        stack.append(to)

print(sum(C[1:]))
print(' '.join(map(str,ans)))