n = int(input())
graph = [[] for _ in range(n)]
cnt = [0] * (n)
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

C = list(map(int, input().split()))
C.sort(reverse=True)
num = sum(C[1:])

ans = [0] * (n)

start = 0
par = [-1] * n
stack = [start]
idx = 0
ans[0] = C[idx]
idx += 1
while stack:
    v = stack.pop()
    for u in graph[v]:
        if u == par[v]:
            continue
        par[u] = v
        ans[u] = C[idx]
        idx += 1
        stack.append(u)
    # print(stack)

print(num)
print(*ans, sep=" ") 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) [] graph = [[] for _ in range(n)] graph [[] for _ in range(n)] cnt = [0] * (n) cnt [0] * (n) [0] 0 n for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[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 graph[a].append(b) [a].append [a] graph a append b graph[b].append(a) [b].append [b] graph 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 num = sum(C[1:]) num sum(C[1:]) sum C[1:] C 1: 1 ans = [0] * (n) ans [0] * (n) [0] 0 n start = 0 start 0 par = [-1] * n par [-1] * n [-1] -1 n stack = [start] stack [start] start idx = 0 idx 0 ans[0] = C[idx] ans[0] ans 0 C[idx] C idx idx += 1 idx 1 while stack:
    v = stack.pop()
    for u in graph[v]:
        if u == par[v]:
            continue
        par[u] = v
        ans[u] = C[idx]
        idx += 1
        stack.append(u)
    # print(stack) stack v = stack.pop() v stack.pop() stack.pop stack pop for u in graph[v]:
        if u == par[v]:
            continue
        par[u] = v
        ans[u] = C[idx]
        idx += 1
        stack.append(u)
    # print(stack) u graph[v] graph v if u == par[v]:
            continue
         u == par[v] u par[v] par v continue par[u] = v par[u] par u v ans[u] = C[idx] ans[u] ans u C[idx] C idx idx += 1 idx 1 stack.append(u) stack.append stack append u print(num) print num print(*ans, sep=" ") print *ans ans sep=" " sep " " start = 0 0 start graph = [[] for _ in range(n)] [[] for _ in range(n)] graph num = sum(C[1:]) sum(C[1:]) num b -= 1 1 b ans = [0] * (n) [0] * (n) ans idx += 1 1 idx idx += 1 1 idx idx = 0 0 idx n = int(input()) int(input()) n a, b = map(int, input().split()) map(int, input().split()) a cnt = [0] * (n) [0] * (n) cnt a -= 1 1 a b = map(int, input().split()) map(int, input().split()) b C = list(map(int, input().split())) list(map(int, input().split())) C v = stack.pop() stack.pop() v stack = [start] [start] stack par = [-1] * n [-1] * n par
n = int(input())
graph = [[] for _ in range(n)]
cnt = [0] * (n)
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

C = list(map(int, input().split()))
C.sort(reverse=True)
num = sum(C[1:])

ans = [0] * (n)

start = 0
par = [-1] * n
stack = [start]
idx = 0
ans[0] = C[idx]
idx += 1
while stack:
    v = stack.pop()
    for u in graph[v]:
        if u == par[v]:
            continue
        par[u] = v
        ans[u] = C[idx]
        idx += 1
        stack.append(u)
    # print(stack)

print(num)
print(*ans, sep=" ")
