import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
clst = list(map(int, input().split()))
clst.sort(reverse = True)
ans = [0 for _ in range(n)]
ind = 0
total = 0
def dfs(pos, b_pos, b_num):
    global ind, total
    ans[pos] = clst[ind]
    total += min(ans[pos], b_num)
    ind += 1
    for n_pos in edges[pos]:
        if n_pos == b_pos:
            continue
        dfs(n_pos, pos, ans[pos])
        
dfs(0, -1, 0)
print(total)
print(*ans) import sys sys sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 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) [] edges = [[] for _ in range(n)] edges [[] for _ in range(n)] for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[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 a -= 1 a 1 b -= 1 b 1 edges[a].append(b) [a].append [a] edges a append b edges[b].append(a) [b].append [b] edges b append a clst = list(map(int, input().split())) clst list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split clst.sort(reverse = True) clst.sort clst sort reverse = True reverse True 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 ans = [0 for _ in range(n)] ans [0 for _ in range(n)] ind = 0 ind 0 total = 0 total 0 def dfs(pos, b_pos, b_num):
    global ind, total
    ans[pos] = clst[ind]
    total += min(ans[pos], b_num)
    ind += 1
    for n_pos in edges[pos]:
        if n_pos == b_pos:
            continue
        dfs(n_pos, pos, ans[pos])
         dfs global ind, total ans[pos] = clst[ind] ans[pos] ans pos clst[ind] clst ind total += min(ans[pos], b_num) total min(ans[pos], b_num) min ans[pos] ans pos b_num ind += 1 ind 1 for n_pos in edges[pos]:
        if n_pos == b_pos:
            continue
        dfs(n_pos, pos, ans[pos])
         n_pos edges[pos] edges pos if n_pos == b_pos:
            continue
         n_pos == b_pos n_pos b_pos continue dfs(n_pos, pos, ans[pos]) dfs n_pos pos ans[pos] ans pos pos pos b_pos b_pos b_num b_num dfs(0, -1, 0) dfs 0 -1 0 print(total) print total print(*ans) print *ans ans ans = [0 for _ in range(n)] [0 for _ in range(n)] ans total = 0 0 total b = map(int, input().split()) map(int, input().split()) b def dfs(pos, b_pos, b_num):
    global ind, total
    ans[pos] = clst[ind]
    total += min(ans[pos], b_num)
    ind += 1
    for n_pos in edges[pos]:
        if n_pos == b_pos:
            continue
        dfs(n_pos, pos, ans[pos])
         def dfs(pos, b_pos, b_num):
    global ind, total
    ans[pos] = clst[ind]
    total += min(ans[pos], b_num)
    ind += 1
    for n_pos in edges[pos]:
        if n_pos == b_pos:
            continue
        dfs(n_pos, pos, ans[pos])
         dfs edges = [[] for _ in range(n)] [[] for _ in range(n)] edges a, b = map(int, input().split()) map(int, input().split()) a n = int(input()) int(input()) n a -= 1 1 a b -= 1 1 b clst = list(map(int, input().split())) list(map(int, input().split())) clst ind = 0 0 ind
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
clst = list(map(int, input().split()))
clst.sort(reverse = True)
ans = [0 for _ in range(n)]
ind = 0
total = 0
def dfs(pos, b_pos, b_num):
    global ind, total
    ans[pos] = clst[ind]
    total += min(ans[pos], b_num)
    ind += 1
    for n_pos in edges[pos]:
        if n_pos == b_pos:
            continue
        dfs(n_pos, pos, ans[pos])
        
dfs(0, -1, 0)
print(total)
print(*ans)