from collections import defaultdict, deque

N = int(input())
adj_list = defaultdict(list)
E = []
V_number = [None]*N
for _ in range(N-1):
    a, b = map(int, input().split())
    E.append((a, b))
    adj_list[a].append(b)
    adj_list[b].append(a)
C = sorted(list(map(int, input().split())), reverse=True)
q = deque([1])
i = 0
while q:
    v = q.popleft()
    V_number[v-1] = C[i]
    i += 1
    for u in adj_list[v]:
        if V_number[u-1] is None:
            q.append(u)

print(sum(C[1:]))
print(*V_number) from collections import defaultdict, deque N = int(input()) N int(input()) int input() input adj_list = defaultdict(list) adj_list defaultdict(list) defaultdict list E = [] E [] V_number = [None]*N V_number [None]*N [None] None N for _ in range(N-1):
    a, b = map(int, input().split())
    E.append((a, b))
    adj_list[a].append(b)
    adj_list[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 E.append((a, b)) E.append E append (a, b) a b 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 = sorted(list(map(int, input().split())), reverse=True) C sorted(list(map(int, input().split())), reverse=True) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split reverse=True reverse True q = deque([1]) q deque([1]) deque [1] 1 i = 0 i 0 while q:
    v = q.popleft()
    V_number[v-1] = C[i]
    i += 1
    for u in adj_list[v]:
        if V_number[u-1] is None:
            q.append(u) q v = q.popleft() v q.popleft() q.popleft q popleft V_number[v-1] = C[i] V_number[v-1] V_number v-1 v 1 C[i] C i i += 1 i 1 for u in adj_list[v]:
        if V_number[u-1] is None:
            q.append(u) u adj_list[v] adj_list v if V_number[u-1] is None:
            q.append(u) V_number[u-1] is None V_number[u-1] V_number u-1 u 1 None q.append(u) q.append q append u print(sum(C[1:])) print sum(C[1:]) sum C[1:] C 1: 1 print(*V_number) print *V_number V_number a, b = map(int, input().split()) map(int, input().split()) a adj_list = defaultdict(list) defaultdict(list) adj_list b = map(int, input().split()) map(int, input().split()) b v = q.popleft() q.popleft() v V_number = [None]*N [None]*N V_number q = deque([1]) deque([1]) q i = 0 0 i N = int(input()) int(input()) N C = sorted(list(map(int, input().split())), reverse=True) sorted(list(map(int, input().split())), reverse=True) C E = [] [] E i += 1 1 i
from collections import defaultdict, deque

N = int(input())
adj_list = defaultdict(list)
E = []
V_number = [None]*N
for _ in range(N-1):
    a, b = map(int, input().split())
    E.append((a, b))
    adj_list[a].append(b)
    adj_list[b].append(a)
C = sorted(list(map(int, input().split())), reverse=True)
q = deque([1])
i = 0
while q:
    v = q.popleft()
    V_number[v-1] = C[i]
    i += 1
    for u in adj_list[v]:
        if V_number[u-1] is None:
            q.append(u)

print(sum(C[1:]))
print(*V_number)