N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
C = [int(i) for i in input().split()]

C.sort()

M = sum(C[:-1])
d = [-1] * N

from collections import deque

que = deque([0])
while que:
    v = que.popleft()
    d[v] = C.pop()
    for w in edge[v]:
        if d[w] < 0:
            que.append(w)

print(M)
print(*d) N = int(input()) N int(input()) int input() input [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] edge = [[] for _ in range(N)] edge [[] for _ in range(N)] for _ in range(N - 1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1) _ 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 edge[a-1].append(b-1) [a-1].append [a-1] edge a-1 a 1 append b-1 b 1 edge[b-1].append(a-1) [b-1].append [b-1] edge b-1 b 1 append a-1 a 1 int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i C = [int(i) for i in input().split()] C [int(i) for i in input().split()] C.sort() C.sort C sort M = sum(C[:-1]) M sum(C[:-1]) sum C[:-1] C :-1 -1 d = [-1] * N d [-1] * N [-1] -1 N from collections import deque que = deque([0]) que deque([0]) deque [0] 0 while que:
    v = que.popleft()
    d[v] = C.pop()
    for w in edge[v]:
        if d[w] < 0:
            que.append(w) que v = que.popleft() v que.popleft() que.popleft que popleft d[v] = C.pop() d[v] d v C.pop() C.pop C pop for w in edge[v]:
        if d[w] < 0:
            que.append(w) w edge[v] edge v if d[w] < 0:
            que.append(w) d[w] < 0 d[w] d w 0 que.append(w) que.append que append w print(M) print M print(*d) print *d d edge = [[] for _ in range(N)] [[] for _ in range(N)] edge C = [int(i) for i in input().split()] [int(i) for i in input().split()] C M = sum(C[:-1]) sum(C[:-1]) M N = int(input()) int(input()) N a,b = map(int, input().split()) map(int, input().split()) a b = map(int, input().split()) map(int, input().split()) b d = [-1] * N [-1] * N d que = deque([0]) deque([0]) que v = que.popleft() que.popleft() v
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
C = [int(i) for i in input().split()]

C.sort()

M = sum(C[:-1])
d = [-1] * N

from collections import deque

que = deque([0])
while que:
    v = que.popleft()
    d[v] = C.pop()
    for w in edge[v]:
        if d[w] < 0:
            que.append(w)

print(M)
print(*d)