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

C.sort(reverse=True)
M = sum(C) - C[0]

from collections import deque
q = deque([0])
ans = [0]*N
ans[0] = C[0]
i = 1
while q:
    u = q.popleft()
    for v in E[u]:
        if ans[v] > 0:
            continue
        ans[v] = C[i]
        i += 1
        q.append(v)

print(M)
print(*ans) 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) [] E = [[] for _ in range(N)] E [[] for _ in range(N)] for _ in range(N-1):
    a,b = map(int, input().split())
    E[a-1].append(b-1)
    E[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 E[a-1].append(b-1) [a-1].append [a-1] E a-1 a 1 append b-1 b 1 E[b-1].append(a-1) [b-1].append [b-1] E b-1 b 1 append a-1 a 1 int(c) for c in input().split() for c in input().split() c input().split() ().split () input split for c in input().split() int(c) int c C = [int(c) for c in input().split()] C [int(c) for c in input().split()] C.sort(reverse=True) C.sort C sort reverse=True reverse True M = sum(C) - C[0] M sum(C) - C[0] sum(C) sum C C[0] C 0 from collections import deque q = deque([0]) q deque([0]) deque [0] 0 ans = [0]*N ans [0]*N [0] 0 N ans[0] = C[0] ans[0] ans 0 C[0] C 0 i = 1 i 1 while q:
    u = q.popleft()
    for v in E[u]:
        if ans[v] > 0:
            continue
        ans[v] = C[i]
        i += 1
        q.append(v) q u = q.popleft() u q.popleft() q.popleft q popleft for v in E[u]:
        if ans[v] > 0:
            continue
        ans[v] = C[i]
        i += 1
        q.append(v) v E[u] E u if ans[v] > 0:
            continue
         ans[v] > 0 ans[v] ans v 0 continue ans[v] = C[i] ans[v] ans v C[i] C i i += 1 i 1 q.append(v) q.append q append v print(M) print M print(*ans) print *ans ans q = deque([0]) deque([0]) q M = sum(C) - C[0] sum(C) - C[0] M ans = [0]*N [0]*N ans i = 1 1 i u = q.popleft() q.popleft() u C = [int(c) for c in input().split()] [int(c) for c in input().split()] C E = [[] for _ in range(N)] [[] for _ in range(N)] E b = map(int, input().split()) map(int, input().split()) b a,b = map(int, input().split()) map(int, input().split()) a N = int(input()) int(input()) N i += 1 1 i
N = int(input())
E = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
C = [int(c) for c in input().split()]

C.sort(reverse=True)
M = sum(C) - C[0]

from collections import deque
q = deque([0])
ans = [0]*N
ans[0] = C[0]
i = 1
while q:
    u = q.popleft()
    for v in E[u]:
        if ans[v] > 0:
            continue
        ans[v] = C[i]
        i += 1
        q.append(v)

print(M)
print(*ans)