N = int(input())
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
*C, = sorted(map(int,input().split()))
print(sum(C[:-1]))
E = [[] for _ in [0]*N]
d = [0]*N
for a,b in AB:
    E[a-1].append(b-1)
    E[b-1].append(a-1)

for i in range(N):
    if len(E[i])>1:break
q = [i]
while q:
    i = q.pop()
    d[i] = C.pop()
    for j in E[i]:
        if d[j] != 0:continue
        q.append(j)
print(*d) N = int(input()) N int(input()) int input() input list(map(int,input().split())) for _ in [0]*(N-1) for _ in [0]*(N-1) _ [0]*(N-1) [0] 0 N-1 N 1 for _ in [0]*(N-1) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split AB = [list(map(int,input().split())) for _ in [0]*(N-1)] AB [list(map(int,input().split())) for _ in [0]*(N-1)] *C, = sorted(map(int,input().split())) *C C sorted(map(int,input().split())) sorted 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 [] for _ in [0]*N for _ in [0]*N _ [0]*N [0] 0 N for _ in [0]*N [] E = [[] for _ in [0]*N] E [[] for _ in [0]*N] d = [0]*N d [0]*N [0] 0 N for a,b in AB:
    E[a-1].append(b-1)
    E[b-1].append(a-1) a b AB E[a-1].append(b-1) [a-1].append [a-1] E a-1 a 1 append b-1 b 1 E[b-1].append(a-1) [b-1].append [b-1] E b-1 b 1 append a-1 a 1 for i in range(N):
    if len(E[i])>1:break i range(N) range N if len(E[i])>1:b len(E[i])>1 len(E[i]) len E[i] E i 1 q = [i] q [i] i while q:
    i = q.pop()
    d[i] = C.pop()
    for j in E[i]:
        if d[j] != 0:continue
        q.append(j) q i = q.pop() i q.pop() q.pop q pop d[i] = C.pop() d[i] d i C.pop() C.pop C pop for j in E[i]:
        if d[j] != 0:continue
        q.append(j) j E[i] E i if d[j] != 0:continue
         d[j] != 0 d[j] d j 0 q.append(j) q.append q append j print(*d) print *d d AB = [list(map(int,input().split())) for _ in [0]*(N-1)] [list(map(int,input().split())) for _ in [0]*(N-1)] AB d = [0]*N [0]*N d i = q.pop() q.pop() i N = int(input()) int(input()) N E = [[] for _ in [0]*N] [[] for _ in [0]*N] E q = [i] [i] q
N = int(input())
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
*C, = sorted(map(int,input().split()))
print(sum(C[:-1]))
E = [[] for _ in [0]*N]
d = [0]*N
for a,b in AB:
    E[a-1].append(b-1)
    E[b-1].append(a-1)

for i in range(N):
    if len(E[i])>1:break
q = [i]
while q:
    i = q.pop()
    d[i] = C.pop()
    for j in E[i]:
        if d[j] != 0:continue
        q.append(j)
print(*d)