from collections import deque

def bfs():
    q = deque()
    q.append(1)
    ans = [0] * n
    i = 0
    while q:
        p = q.popleft()
        ans[p - 1] = c[i]
        i += 1
        for j in G[p]:
            if ans[j - 1] == 0:
                q.append(j)
    return ans

n = int(input())
G = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse = True)
s = sum(c) - c[0]
ans = bfs()
print(s)
print(*ans) from collections import deque def bfs():
    q = deque()
    q.append(1)
    ans = [0] * n
    i = 0
    while q:
        p = q.popleft()
        ans[p - 1] = c[i]
        i += 1
        for j in G[p]:
            if ans[j - 1] == 0:
                q.append(j)
    return ans bfs q = deque() q deque() deque q.append(1) q.append q append 1 ans = [0] * n ans [0] * n [0] 0 n i = 0 i 0 while q:
        p = q.popleft()
        ans[p - 1] = c[i]
        i += 1
        for j in G[p]:
            if ans[j - 1] == 0:
                q.append(j)
     q p = q.popleft() p q.popleft() q.popleft q popleft ans[p - 1] = c[i] ans[p - 1] ans p - 1 p 1 c[i] c i i += 1 i 1 for j in G[p]:
            if ans[j - 1] == 0:
                q.append(j)
     j G[p] G p if ans[j - 1] == 0:
                q.append(j)
     ans[j - 1] == 0 ans[j - 1] ans j - 1 j 1 0 q.append(j) q.append q append j return ans ans n = int(input()) n int(input()) int input() input [] for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [] G = [[] for _ in range(n + 1)] G [[] for _ in range(n + 1)] for _ in range(n - 1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a) _ 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 G[a].append(b) [a].append [a] G a append b G[b].append(a) [b].append [b] G 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 = True) c.sort c sort reverse = True reverse True s = sum(c) - c[0] s sum(c) - c[0] sum(c) sum c c[0] c 0 ans = bfs() ans bfs() bfs print(s) print s print(*ans) print *ans ans c = list(map(int, input().split())) list(map(int, input().split())) c s = sum(c) - c[0] sum(c) - c[0] s G = [[] for _ in range(n + 1)] [[] for _ in range(n + 1)] G b = map(int, input().split()) map(int, input().split()) b ans = bfs() bfs() ans def bfs():
    q = deque()
    q.append(1)
    ans = [0] * n
    i = 0
    while q:
        p = q.popleft()
        ans[p - 1] = c[i]
        i += 1
        for j in G[p]:
            if ans[j - 1] == 0:
                q.append(j)
    return ans def bfs():
    q = deque()
    q.append(1)
    ans = [0] * n
    i = 0
    while q:
        p = q.popleft()
        ans[p - 1] = c[i]
        i += 1
        for j in G[p]:
            if ans[j - 1] == 0:
                q.append(j)
    return ans bfs a, b = map(int, input().split()) map(int, input().split()) a n = int(input()) int(input()) n
from collections import deque

def bfs():
    q = deque()
    q.append(1)
    ans = [0] * n
    i = 0
    while q:
        p = q.popleft()
        ans[p - 1] = c[i]
        i += 1
        for j in G[p]:
            if ans[j - 1] == 0:
                q.append(j)
    return ans

n = int(input())
G = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse = True)
s = sum(c) - c[0]
ans = bfs()
print(s)
print(*ans)