from collections import defaultdict
N = int(input())
dic = defaultdict(list)
for n in range(N - 1):
    a, b = map(int, input().split())
    dic[a].append(b)
    dic[b].append(a)
c_list = sorted(map(int, input().split()))
M = sum(c_list[:-1])
d_list = [False] * N
for i in range(1, N + 1):
    if len(dic[i]) == 1:
        break
blank = N
q = [i]
while blank:
    i = q.pop(0)
    if not d_list[i - 1]:
        q += dic[i]
        d_list[i - 1] = c_list[blank - 1]
        blank -= 1
print(M)
print(' '.join(map(str, d_list))) from collections import defaultdict N = int(input()) N int(input()) int input() input dic = defaultdict(list) dic defaultdict(list) defaultdict list for n in range(N - 1):
    a, b = map(int, input().split())
    dic[a].append(b)
    dic[b].append(a) n 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 dic[a].append(b) [a].append [a] dic a append b dic[b].append(a) [b].append [b] dic b append a c_list = sorted(map(int, input().split())) c_list sorted(map(int, input().split())) sorted map(int, input().split()) map int input().split() ().split () input split M = sum(c_list[:-1]) M sum(c_list[:-1]) sum c_list[:-1] c_list :-1 -1 d_list = [False] * N d_list [False] * N [False] False N for i in range(1, N + 1):
    if len(dic[i]) == 1:
        break i range(1, N + 1) range 1 N + 1 N 1 if len(dic[i]) == 1:
        break len(dic[i]) == 1 len(dic[i]) len dic[i] dic i 1 break blank = N blank N q = [i] q [i] i while blank:
    i = q.pop(0)
    if not d_list[i - 1]:
        q += dic[i]
        d_list[i - 1] = c_list[blank - 1]
        blank -= 1 blank i = q.pop(0) i q.pop(0) q.pop q pop 0 if not d_list[i - 1]:
        q += dic[i]
        d_list[i - 1] = c_list[blank - 1]
        blank -= 1 not d_list[i - 1] d_list[i - 1] d_list i - 1 i 1 q += dic[i] q dic[i] dic i d_list[i - 1] = c_list[blank - 1] d_list[i - 1] d_list i - 1 i 1 c_list[blank - 1] c_list blank - 1 blank 1 blank -= 1 blank 1 print(M) print M print(' '.join(map(str, d_list))) print ' '.join(map(str, d_list)) ' '.join ' ' join map(str, d_list) map str d_list i = q.pop(0) q.pop(0) i q += dic[i] dic[i] q b = map(int, input().split()) map(int, input().split()) b blank -= 1 1 blank a, b = map(int, input().split()) map(int, input().split()) a M = sum(c_list[:-1]) sum(c_list[:-1]) M N = int(input()) int(input()) N dic = defaultdict(list) defaultdict(list) dic d_list = [False] * N [False] * N d_list q = [i] [i] q blank = N N blank c_list = sorted(map(int, input().split())) sorted(map(int, input().split())) c_list
from collections import defaultdict
N = int(input())
dic = defaultdict(list)
for n in range(N - 1):
    a, b = map(int, input().split())
    dic[a].append(b)
    dic[b].append(a)
c_list = sorted(map(int, input().split()))
M = sum(c_list[:-1])
d_list = [False] * N
for i in range(1, N + 1):
    if len(dic[i]) == 1:
        break
blank = N
q = [i]
while blank:
    i = q.pop(0)
    if not d_list[i - 1]:
        q += dic[i]
        d_list[i - 1] = c_list[blank - 1]
        blank -= 1
print(M)
print(' '.join(map(str, d_list)))