from collections import deque

N = int(input())
ki = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ki[a].append(b)
    ki[b].append(a)
#print(ki)
c = list(map(int,input().split()))
c.sort()
c.reverse()
point = 1
lis = [0] * N
que = deque([0])
lis[0] = c[0]
while len(que) != 0:
    p = que.popleft()
    #print(p)
    for i in ki[p]:
        if lis[i] == 0:
            que.append(i)
            lis[i] = c[point]
            point += 1
print(sum(c)-c[0])
print(' '.join(map(str,lis))) 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) [] ki = [[] for i in range(N)] ki [[] for i in range(N)] for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ki[a].append(b)
    ki[b].append(a)
#print(ki) 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 ki[a].append(b) [a].append [a] ki a append b ki[b].append(a) [b].append [b] ki 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() c.sort c sort c.reverse() c.reverse c reverse point = 1 point 1 lis = [0] * N lis [0] * N [0] 0 N que = deque([0]) que deque([0]) deque [0] 0 lis[0] = c[0] lis[0] lis 0 c[0] c 0 while len(que) != 0:
    p = que.popleft()
    #print(p)
    for i in ki[p]:
        if lis[i] == 0:
            que.append(i)
            lis[i] = c[point]
            point += 1 len(que) != 0 len(que) len que 0 p = que.popleft() p que.popleft() que.popleft que popleft for i in ki[p]:
        if lis[i] == 0:
            que.append(i)
            lis[i] = c[point]
            point += 1 i ki[p] ki p if lis[i] == 0:
            que.append(i)
            lis[i] = c[point]
            point += 1 lis[i] == 0 lis[i] lis i 0 que.append(i) que.append que append i lis[i] = c[point] lis[i] lis i c[point] c point point += 1 point 1 print(sum(c)-c[0]) print sum(c)-c[0] sum(c) sum c c[0] c 0 print(' '.join(map(str,lis))) print ' '.join(map(str,lis)) ' '.join ' ' join map(str,lis) map str lis ki = [[] for i in range(N)] [[] for i in range(N)] ki a,b = map(int,input().split()) map(int,input().split()) a p = que.popleft() que.popleft() p b -= 1 1 b point += 1 1 point N = int(input()) int(input()) N b = map(int,input().split()) map(int,input().split()) b a -= 1 1 a point = 1 1 point lis = [0] * N [0] * N lis que = deque([0]) deque([0]) que c = list(map(int,input().split())) list(map(int,input().split())) c
from collections import deque

N = int(input())
ki = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ki[a].append(b)
    ki[b].append(a)
#print(ki)
c = list(map(int,input().split()))
c.sort()
c.reverse()
point = 1
lis = [0] * N
que = deque([0])
lis[0] = c[0]
while len(que) != 0:
    p = que.popleft()
    #print(p)
    for i in ki[p]:
        if lis[i] == 0:
            que.append(i)
            lis[i] = c[point]
            point += 1
print(sum(c)-c[0])
print(' '.join(map(str,lis)))
