N = int(input())
edges = [list(map(int, input().split())) for i in range(N-1)]
c = list(map(int, input().split()))
c.sort(reverse=True)
_c = c[::]

conn = [[] for i in range(N)]
for edge in edges:
    a = edge[0]-1
    b = edge[1]-1
    conn[a].append(b)
    conn[b].append(a)
ans = [0 for i in range(N)]
stack = []
stack.append(0)
checked = set()
while len(stack) > 0:
    current = stack.pop(0)
    checked.add(current)
    ans[current] = c[0]
    c.pop(0)
    for next in conn[current]:
        if next not in checked:
            stack.append(next)

print(sum(_c[1:]))
ans_str = ""
for i in range(N):
    ans_str += str(ans[i])
    if i < N-1:
        ans_str += " "
print(ans_str)




 N = int(input()) N int(input()) int input() input list(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) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split edges = [list(map(int, input().split())) for i in range(N-1)] edges [list(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(reverse=True) c.sort c sort reverse=True reverse True _c = c[::] _c c[::] c :: [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] conn = [[] for i in range(N)] conn [[] for i in range(N)] for edge in edges:
    a = edge[0]-1
    b = edge[1]-1
    conn[a].append(b)
    conn[b].append(a) edge edges a = edge[0]-1 a edge[0]-1 edge[0] edge 0 1 b = edge[1]-1 b edge[1]-1 edge[1] edge 1 1 conn[a].append(b) [a].append [a] conn a append b conn[b].append(a) [b].append [b] conn b append a 0 for i in range(N) for i in range(N) i range(N) range N for i in range(N) 0 ans = [0 for i in range(N)] ans [0 for i in range(N)] stack = [] stack [] stack.append(0) stack.append stack append 0 checked = set() checked set() set while len(stack) > 0:
    current = stack.pop(0)
    checked.add(current)
    ans[current] = c[0]
    c.pop(0)
    for next in conn[current]:
        if next not in checked:
            stack.append(next) len(stack) > 0 len(stack) len stack 0 current = stack.pop(0) current stack.pop(0) stack.pop stack pop 0 checked.add(current) checked.add checked add current ans[current] = c[0] ans[current] ans current c[0] c 0 c.pop(0) c.pop c pop 0 for next in conn[current]:
        if next not in checked:
            stack.append(next) next conn[current] conn current if next not in checked:
            stack.append(next) next not in checked next checked stack.append(next) stack.append stack append next print(sum(_c[1:])) print sum(_c[1:]) sum _c[1:] _c 1: 1 ans_str = "" ans_str "" for i in range(N):
    ans_str += str(ans[i])
    if i < N-1:
        ans_str += " " i range(N) range N ans_str += str(ans[i]) ans_str str(ans[i]) str ans[i] ans i if i < N-1:
        ans_str += " " i < N-1 i N-1 N 1 ans_str += " " ans_str " " print(ans_str) print ans_str ans = [0 for i in range(N)] [0 for i in range(N)] ans N = int(input()) int(input()) N edges = [list(map(int, input().split())) for i in range(N-1)] [list(map(int, input().split())) for i in range(N-1)] edges conn = [[] for i in range(N)] [[] for i in range(N)] conn _c = c[::] c[::] _c checked = set() set() checked stack = [] [] stack c = list(map(int, input().split())) list(map(int, input().split())) c ans_str += str(ans[i]) str(ans[i]) ans_str ans_str += " " " " ans_str ans_str = "" "" ans_str a = edge[0]-1 edge[0]-1 a b = edge[1]-1 edge[1]-1 b current = stack.pop(0) stack.pop(0) current
N = int(input())
edges = [list(map(int, input().split())) for i in range(N-1)]
c = list(map(int, input().split()))
c.sort(reverse=True)
_c = c[::]

conn = [[] for i in range(N)]
for edge in edges:
    a = edge[0]-1
    b = edge[1]-1
    conn[a].append(b)
    conn[b].append(a)
ans = [0 for i in range(N)]
stack = []
stack.append(0)
checked = set()
while len(stack) > 0:
    current = stack.pop(0)
    checked.add(current)
    ans[current] = c[0]
    c.pop(0)
    for next in conn[current]:
        if next not in checked:
            stack.append(next)

print(sum(_c[1:]))
ans_str = ""
for i in range(N):
    ans_str += str(ans[i])
    if i < N-1:
        ans_str += " "
print(ans_str)





