from collections import deque
ov = deque([0])
n = int(input())
e = [[int(_)-1 for _ in input().split()] for __ in range(n-1)]
c = sorted([int(_) for _ in input().split()])
m = sum(c[:-1])
d = [0 for _ in range(n)]
adv = [[] for _ in range(n)]
for i in range(n-1):
    adv[e[i][0]].append(e[i][1])
    adv[e[i][1]].append(e[i][0])
while len(ov) > 0:
    i = ov.popleft()
    d[i] = c.pop()
    for j in range(len(adv[i])):
        if d[adv[i][j]] == 0:
            ov.append(adv[i][j])
print(m); print(' '.join([str(_) for _ in d])) from collections import deque ov = deque([0]) ov deque([0]) deque [0] 0 n = int(input()) n int(input()) int input() input [int(_)-1 for _ in 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) [int(_)-1 for _ in input().split()] e = [[int(_)-1 for _ in input().split()] for __ in range(n-1)] e [[int(_)-1 for _ in input().split()] for __ in range(n-1)] int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ c = sorted([int(_) for _ in input().split()]) c sorted([int(_) for _ in input().split()]) sorted [int(_) for _ in input().split()] m = sum(c[:-1]) m sum(c[:-1]) sum c[:-1] c :-1 -1 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 d = [0 for _ in range(n)] d [0 for _ in range(n)] [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] adv = [[] for _ in range(n)] adv [[] for _ in range(n)] for i in range(n-1):
    adv[e[i][0]].append(e[i][1])
    adv[e[i][1]].append(e[i][0]) i range(n-1) range n-1 n 1 adv[e[i][0]].append(e[i][1]) [e[i][0]].append [e[i][0]] adv e[i][0] [i] e i 0 append e[i][1] [i] e i 1 adv[e[i][1]].append(e[i][0]) [e[i][1]].append [e[i][1]] adv e[i][1] [i] e i 1 append e[i][0] [i] e i 0 while len(ov) > 0:
    i = ov.popleft()
    d[i] = c.pop()
    for j in range(len(adv[i])):
        if d[adv[i][j]] == 0:
            ov.append(adv[i][j]) len(ov) > 0 len(ov) len ov 0 i = ov.popleft() i ov.popleft() ov.popleft ov popleft d[i] = c.pop() d[i] d i c.pop() c.pop c pop for j in range(len(adv[i])):
        if d[adv[i][j]] == 0:
            ov.append(adv[i][j]) j range(len(adv[i])) range len(adv[i]) len adv[i] adv i if d[adv[i][j]] == 0:
            ov.append(adv[i][j]) d[adv[i][j]] == 0 d[adv[i][j]] d adv[i][j] [i] adv i j 0 ov.append(adv[i][j]) ov.append ov append adv[i][j] [i] adv i j str(_) for _ in d for _ in d _ d for _ in d str(_) str _ print(m) print m print(' '.join([str(_) for _ in d])) print ' '.join([str(_) for _ in d]) ' '.join ' ' join [str(_) for _ in d] adv = [[] for _ in range(n)] [[] for _ in range(n)] adv ov = deque([0]) deque([0]) ov m = sum(c[:-1]) sum(c[:-1]) m d = [0 for _ in range(n)] [0 for _ in range(n)] d c = sorted([int(_) for _ in input().split()]) sorted([int(_) for _ in input().split()]) c n = int(input()) int(input()) n e = [[int(_)-1 for _ in input().split()] for __ in range(n-1)] [[int(_)-1 for _ in input().split()] for __ in range(n-1)] e i = ov.popleft() ov.popleft() i
from collections import deque
ov = deque([0])
n = int(input())
e = [[int(_)-1 for _ in input().split()] for __ in range(n-1)]
c = sorted([int(_) for _ in input().split()])
m = sum(c[:-1])
d = [0 for _ in range(n)]
adv = [[] for _ in range(n)]
for i in range(n-1):
    adv[e[i][0]].append(e[i][1])
    adv[e[i][1]].append(e[i][0])
while len(ov) > 0:
    i = ov.popleft()
    d[i] = c.pop()
    for j in range(len(adv[i])):
        if d[adv[i][j]] == 0:
            ov.append(adv[i][j])
print(m); print(' '.join([str(_) for _ in d]))