from collections import deque
N = int(input())
es = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    es[a].append(b)
    es[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse=1)
q = deque()
q.append(0)
flg = [0]*N
num = [None]*N
i = 0
while len(q):
    v = q.popleft()
    flg[v] = 1
    num[v] = c[i]
    i += 1
    for u in es[v]:
        if flg[u]:
            continue
        q.append(u)
print(sum(c[1:]))
print(*num)

 from collections import deque N = int(input()) N int(input()) int input() input [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] es = [[] for i in range(N)] es [[] for i in range(N)] for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    es[a].append(b)
    es[b].append(a) i range(N-1) range N-1 N 1 a, b = map(lambda x: int(x)-1, input().split()) a map(lambda x: int(x)-1, input().split()) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split b es[a].append(b) [a].append [a] es a append b es[b].append(a) [b].append [b] es 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=1) c.sort c sort reverse=1 reverse 1 q = deque() q deque() deque q.append(0) q.append q append 0 flg = [0]*N flg [0]*N [0] 0 N num = [None]*N num [None]*N [None] None N i = 0 i 0 while len(q):
    v = q.popleft()
    flg[v] = 1
    num[v] = c[i]
    i += 1
    for u in es[v]:
        if flg[u]:
            continue
        q.append(u) len(q) len q v = q.popleft() v q.popleft() q.popleft q popleft flg[v] = 1 flg[v] flg v 1 num[v] = c[i] num[v] num v c[i] c i i += 1 i 1 for u in es[v]:
        if flg[u]:
            continue
        q.append(u) u es[v] es v if flg[u]:
            continue
         flg[u] flg u continue q.append(u) q.append q append u print(sum(c[1:])) print sum(c[1:]) sum c[1:] c 1: 1 print(*num) print *num num q = deque() deque() q num = [None]*N [None]*N num a, b = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) a flg = [0]*N [0]*N flg es = [[] for i in range(N)] [[] for i in range(N)] es c = list(map(int, input().split())) list(map(int, input().split())) c i += 1 1 i b = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) b N = int(input()) int(input()) N i = 0 0 i v = q.popleft() q.popleft() v
from collections import deque
N = int(input())
es = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    es[a].append(b)
    es[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse=1)
q = deque()
q.append(0)
flg = [0]*N
num = [None]*N
i = 0
while len(q):
    v = q.popleft()
    flg[v] = 1
    num[v] = c[i]
    i += 1
    for u in es[v]:
        if flg[u]:
            continue
        q.append(u)
print(sum(c[1:]))
print(*num)


