N=int(input())
G=[[] for _ in range(N)]
for _ in range(N-1):
    a,b=map(int, input().split())
    a,b=a-1,b-1
    G[a].append(b)
    G[b].append(a)
*C,=map(int, input().split())

C.sort(reverse=True)
ans=[-1]*N

stk=[0]
ans[0]=C[0]
idx=1
while stk:
    v=stk.pop()
    for to in G[v]:
        if ans[to]>0: continue
        ans[to]=C[idx]
        idx+=1
        stk.append(to)

print(sum(C)-C[0])
print(*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) [] G=[[] for _ in range(N)] G [[] for _ in range(N)] for _ in range(N-1):
    a,b=map(int, input().split())
    a,b=a-1,b-1
    G[a].append(b)
    G[b].append(a) _ 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 a,b=a-1,b-1 a a-1 a 1 b b-1 b 1 G[a].append(b) [a].append [a] G a append b G[b].append(a) [b].append [b] G b append a *C,=map(int, input().split()) *C C map(int, input().split()) map int input().split() ().split () input split C.sort(reverse=True) C.sort C sort reverse=True reverse True ans=[-1]*N ans [-1]*N [-1] -1 N stk=[0] stk [0] 0 ans[0]=C[0] ans[0] ans 0 C[0] C 0 idx=1 idx 1 while stk:
    v=stk.pop()
    for to in G[v]:
        if ans[to]>0: continue
        ans[to]=C[idx]
        idx+=1
        stk.append(to) stk v=stk.pop() v stk.pop() stk.pop stk pop for to in G[v]:
        if ans[to]>0: continue
        ans[to]=C[idx]
        idx+=1
        stk.append(to) to G[v] G v if ans[to]>0: continue
         ans[to]>0 ans[to] ans to 0 ans[to]=C[idx] ans[to] ans to C[idx] C idx idx+=1 idx 1 stk.append(to) stk.append stk append to print(sum(C)-C[0]) print sum(C)-C[0] sum(C) sum C C[0] C 0 print(*ans) print *ans ans stk=[0] [0] stk a,b=map(int, input().split()) map(int, input().split()) a b=a-1,b-1 b-1 b v=stk.pop() stk.pop() v N=int(input()) int(input()) N idx=1 1 idx idx+=1 1 idx G=[[] for _ in range(N)] [[] for _ in range(N)] G b=map(int, input().split()) map(int, input().split()) b ans=[-1]*N [-1]*N ans a,b=a-1,b-1 a-1 a
N=int(input())
G=[[] for _ in range(N)]
for _ in range(N-1):
    a,b=map(int, input().split())
    a,b=a-1,b-1
    G[a].append(b)
    G[b].append(a)
*C,=map(int, input().split())

C.sort(reverse=True)
ans=[-1]*N

stk=[0]
ans[0]=C[0]
idx=1
while stk:
    v=stk.pop()
    for to in G[v]:
        if ans[to]>0: continue
        ans[to]=C[idx]
        idx+=1
        stk.append(to)

print(sum(C)-C[0])
print(*ans)