n = int(input())
ab = [list(map(int,input().split())) for _ in range(n-1)]
c = list(map(int,input().split()))

c.sort(reverse = True)
edges = [[] for _ in range(n)]
ans = [-1]*n
ans[0] = c[0]
count = 1

for a,b in ab:
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

q = [0]

while q:
    l = q.pop(-1)
    for l1 in edges[l]:
        if ans[l1] == -1:
            q.append(l1)
            ans[l1] = c[count]
            count += 1

print(sum(c[1:]))
for i in ans:
    print(i, end = ' ') n = int(input()) n int(input()) int input() input list(map(int,input().split())) for _ in range(n-1) for _ in range(n-1) _ range(n-1) range n-1 n 1 for _ in range(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 range(n-1)] ab [list(map(int,input().split())) for _ in range(n-1)] 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 [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] edges = [[] for _ in range(n)] edges [[] for _ in range(n)] ans = [-1]*n ans [-1]*n [-1] -1 n ans[0] = c[0] ans[0] ans 0 c[0] c 0 count = 1 count 1 for a,b in ab:
    edges[a-1].append(b-1)
    edges[b-1].append(a-1) a b ab edges[a-1].append(b-1) [a-1].append [a-1] edges a-1 a 1 append b-1 b 1 edges[b-1].append(a-1) [b-1].append [b-1] edges b-1 b 1 append a-1 a 1 q = [0] q [0] 0 while q:
    l = q.pop(-1)
    for l1 in edges[l]:
        if ans[l1] == -1:
            q.append(l1)
            ans[l1] = c[count]
            count += 1 q l = q.pop(-1) l q.pop(-1) q.pop q pop -1 for l1 in edges[l]:
        if ans[l1] == -1:
            q.append(l1)
            ans[l1] = c[count]
            count += 1 l1 edges[l] edges l if ans[l1] == -1:
            q.append(l1)
            ans[l1] = c[count]
            count += 1 ans[l1] == -1 ans[l1] ans l1 -1 q.append(l1) q.append q append l1 ans[l1] = c[count] ans[l1] ans l1 c[count] c count count += 1 count 1 print(sum(c[1:])) print sum(c[1:]) sum c[1:] c 1: 1 for i in ans:
    print(i, end = ' ') i ans print(i, end = ' ') print i end = ' ' end ' ' ab = [list(map(int,input().split())) for _ in range(n-1)] [list(map(int,input().split())) for _ in range(n-1)] ab edges = [[] for _ in range(n)] [[] for _ in range(n)] edges count = 1 1 count q = [0] [0] q n = int(input()) int(input()) n l = q.pop(-1) q.pop(-1) l ans = [-1]*n [-1]*n ans c = list(map(int,input().split())) list(map(int,input().split())) c count += 1 1 count
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n-1)]
c = list(map(int,input().split()))

c.sort(reverse = True)
edges = [[] for _ in range(n)]
ans = [-1]*n
ans[0] = c[0]
count = 1

for a,b in ab:
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

q = [0]

while q:
    l = q.pop(-1)
    for l1 in edges[l]:
        if ans[l1] == -1:
            q.append(l1)
            ans[l1] = c[count]
            count += 1

print(sum(c[1:]))
for i in ans:
    print(i, end = ' ')
