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

stack = [0]
ans = [-1] * N
ans[0] = C.pop()
m = 0
while stack:
    v = stack.pop()
    for to in es[v]:
        if ans[to] >= 0: continue
        ans[to] = C.pop()
        m += ans[to]
        stack.append(to)
print(m)
print(*ans) N = int(input()) N int(input()) int input() input tuple(map(int,input().split())) for i in range(N-1) for i in range(N-1) i range(N-1) range N-1 N 1 for i in range(N-1) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split AB = [tuple(map(int,input().split())) for i in range(N-1)] AB [tuple(map(int,input().split())) for i in range(N-1)] 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() C.sort C sort [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] es = [[] for _ in range(N)] es [[] for _ in range(N)] for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a) a b AB a,b = a-1,b-1 a a-1 a 1 b b-1 b 1 es[a].append(b) [a].append [a] es a append b es[b].append(a) [b].append [b] es b append a stack = [0] stack [0] 0 ans = [-1] * N ans [-1] * N [-1] -1 N ans[0] = C.pop() ans[0] ans 0 C.pop() C.pop C pop m = 0 m 0 while stack:
    v = stack.pop()
    for to in es[v]:
        if ans[to] >= 0: continue
        ans[to] = C.pop()
        m += ans[to]
        stack.append(to) stack v = stack.pop() v stack.pop() stack.pop stack pop for to in es[v]:
        if ans[to] >= 0: continue
        ans[to] = C.pop()
        m += ans[to]
        stack.append(to) to es[v] es v if ans[to] >= 0: continue
         ans[to] >= 0 ans[to] ans to 0 ans[to] = C.pop() ans[to] ans to C.pop() C.pop C pop m += ans[to] m ans[to] ans to stack.append(to) stack.append stack append to print(m) print m print(*ans) print *ans ans v = stack.pop() stack.pop() v AB = [tuple(map(int,input().split())) for i in range(N-1)] [tuple(map(int,input().split())) for i in range(N-1)] AB stack = [0] [0] stack es = [[] for _ in range(N)] [[] for _ in range(N)] es a,b = a-1,b-1 a-1 a m += ans[to] ans[to] m N = int(input()) int(input()) N C = list(map(int,input().split())) list(map(int,input().split())) C b = a-1,b-1 b-1 b ans = [-1] * N [-1] * N ans m = 0 0 m
N = int(input())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
C = list(map(int,input().split()))
C.sort()
es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

stack = [0]
ans = [-1] * N
ans[0] = C.pop()
m = 0
while stack:
    v = stack.pop()
    for to in es[v]:
        if ans[to] >= 0: continue
        ans[to] = C.pop()
        m += ans[to]
        stack.append(to)
print(m)
print(*ans)