N=int(input())
from collections import defaultdict
branch=defaultdict(set)
for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    branch[a]|={b}
    branch[b]|={a}
C=list(map(int,input().split()))
C.sort()
ans=[0]*N
used={0}
check={0}
M=sum(C[:-1])
while len(check)>0:
    now=check.pop()
    ans[now]=C.pop()
    for nex in branch[now]:
        if nex not in used:
            check|={nex}
            used|={nex}
print(M)
print(" ".join([str(x) for x in ans])) N=int(input()) N int(input()) int input() input from collections import defaultdict branch=defaultdict(set) branch defaultdict(set) defaultdict set for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    branch[a]|={b}
    branch[b]|={a} 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 a-=1 a 1 b-=1 b 1 branch[a]|={b} branch[a] branch a {b} branch[b]|={a} branch[b] branch b {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() C.sort C sort ans=[0]*N ans [0]*N [0] 0 N used={0} used {0} check={0} check {0} M=sum(C[:-1]) M sum(C[:-1]) sum C[:-1] C :-1 -1 while len(check)>0:
    now=check.pop()
    ans[now]=C.pop()
    for nex in branch[now]:
        if nex not in used:
            check|={nex}
            used|={nex} len(check)>0 len(check) len check 0 now=check.pop() now check.pop() check.pop check pop ans[now]=C.pop() ans[now] ans now C.pop() C.pop C pop for nex in branch[now]:
        if nex not in used:
            check|={nex}
            used|={nex} nex branch[now] branch now if nex not in used:
            check|={nex}
            used|={nex} nex not in used nex used check|={nex} check {nex} used|={nex} used {nex} print(M) print M str(x) for x in ans for x in ans x ans for x in ans str(x) str x print(" ".join([str(x) for x in ans])) print " ".join([str(x) for x in ans]) " ".join " " join [str(x) for x in ans] C=list(map(int,input().split())) list(map(int,input().split())) C ans=[0]*N [0]*N ans check|={nex} {nex} check N=int(input()) int(input()) N b-=1 1 b a,b=map(int,input().split()) map(int,input().split()) a a-=1 1 a M=sum(C[:-1]) sum(C[:-1]) M check={0} {0} check used|={nex} {nex} used used={0} {0} used branch=defaultdict(set) defaultdict(set) branch b=map(int,input().split()) map(int,input().split()) b now=check.pop() check.pop() now
N=int(input())
from collections import defaultdict
branch=defaultdict(set)
for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    branch[a]|={b}
    branch[b]|={a}
C=list(map(int,input().split()))
C.sort()
ans=[0]*N
used={0}
check={0}
M=sum(C[:-1])
while len(check)>0:
    now=check.pop()
    ans[now]=C.pop()
    for nex in branch[now]:
        if nex not in used:
            check|={nex}
            used|={nex}
print(M)
print(" ".join([str(x) for x in ans]))