n = int(input())

adj_list = [[] for _ in range(n)]

for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj_list[a].append(b)
    adj_list[b].append(a)

c = list(map(int, input().split()))
c.sort(reverse=True)
idx = 0

from collections import deque

dq = deque()

dq.append(0)
ans = [-1] * n

while len(dq) > 0:
    node = dq.popleft()
    ans[node] = c[idx]
    idx += 1
    for next_node in adj_list[node]:
        if ans[next_node] < 0:
            dq.append(next_node)

print(sum(c[1:]))
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) [] adj_list = [[] for _ in range(n)] adj_list [[] for _ in range(n)] for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj_list[a].append(b)
    adj_list[b].append(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 adj_list[a].append(b) [a].append [a] adj_list a append b adj_list[b].append(a) [b].append [b] adj_list 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 idx = 0 idx 0 from collections import deque dq = deque() dq deque() deque dq.append(0) dq.append dq append 0 ans = [-1] * n ans [-1] * n [-1] -1 n while len(dq) > 0:
    node = dq.popleft()
    ans[node] = c[idx]
    idx += 1
    for next_node in adj_list[node]:
        if ans[next_node] < 0:
            dq.append(next_node) len(dq) > 0 len(dq) len dq 0 node = dq.popleft() node dq.popleft() dq.popleft dq popleft ans[node] = c[idx] ans[node] ans node c[idx] c idx idx += 1 idx 1 for next_node in adj_list[node]:
        if ans[next_node] < 0:
            dq.append(next_node) next_node adj_list[node] adj_list node if ans[next_node] < 0:
            dq.append(next_node) ans[next_node] < 0 ans[next_node] ans next_node 0 dq.append(next_node) dq.append dq append next_node print(sum(c[1:])) print sum(c[1:]) sum c[1:] c 1: 1 print(*ans) print *ans ans adj_list = [[] for _ in range(n)] [[] for _ in range(n)] adj_list ans = [-1] * n [-1] * n ans c = list(map(int, input().split())) list(map(int, input().split())) c a -= 1 1 a b -= 1 1 b a, b = map(int, input().split()) map(int, input().split()) a dq = deque() deque() dq idx += 1 1 idx idx = 0 0 idx b = map(int, input().split()) map(int, input().split()) b n = int(input()) int(input()) n node = dq.popleft() dq.popleft() node
n = int(input())

adj_list = [[] for _ in range(n)]

for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj_list[a].append(b)
    adj_list[b].append(a)

c = list(map(int, input().split()))
c.sort(reverse=True)
idx = 0

from collections import deque

dq = deque()

dq.append(0)
ans = [-1] * n

while len(dq) > 0:
    node = dq.popleft()
    ans[node] = c[idx]
    idx += 1
    for next_node in adj_list[node]:
        if ans[next_node] < 0:
            dq.append(next_node)

print(sum(c[1:]))
print(*ans)
