N = int(input())

neighbors = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    neighbors[a].append(b)
    neighbors[b].append(a)
c = list(map(int, input().split()))
sorted_c = sorted(c)

closed = [0 for _ in range(N)]
use = [0 for _ in range(N)]
q = []
q.append(0)
use[0] = sorted_c.pop()
M = 0


while len(q) > 0:
    parent = q.pop()
    closed[parent] = use[parent]
    for neighbor in neighbors[parent]:
        if closed[neighbor] == 0:
            c2 = use[neighbor] = sorted_c.pop()
            c1 = closed[parent]
            M += c2
            q.append(neighbor)

print(M)
print(*use) 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) [] neighbors = [[] for _ in range(N)] neighbors [[] for _ in range(N)] for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    neighbors[a].append(b)
    neighbors[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, b = a - 1, b - 1 a a - 1 a 1 b b - 1 b 1 neighbors[a].append(b) [a].append [a] neighbors a append b neighbors[b].append(a) [b].append [b] neighbors 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 sorted_c = sorted(c) sorted_c sorted(c) sorted c 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 closed = [0 for _ in range(N)] closed [0 for _ in range(N)] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 use = [0 for _ in range(N)] use [0 for _ in range(N)] q = [] q [] q.append(0) q.append q append 0 use[0] = sorted_c.pop() use[0] use 0 sorted_c.pop() sorted_c.pop sorted_c pop M = 0 M 0 while len(q) > 0:
    parent = q.pop()
    closed[parent] = use[parent]
    for neighbor in neighbors[parent]:
        if closed[neighbor] == 0:
            c2 = use[neighbor] = sorted_c.pop()
            c1 = closed[parent]
            M += c2
            q.append(neighbor) len(q) > 0 len(q) len q 0 parent = q.pop() parent q.pop() q.pop q pop closed[parent] = use[parent] closed[parent] closed parent use[parent] use parent for neighbor in neighbors[parent]:
        if closed[neighbor] == 0:
            c2 = use[neighbor] = sorted_c.pop()
            c1 = closed[parent]
            M += c2
            q.append(neighbor) neighbor neighbors[parent] neighbors parent if closed[neighbor] == 0:
            c2 = use[neighbor] = sorted_c.pop()
            c1 = closed[parent]
            M += c2
            q.append(neighbor) closed[neighbor] == 0 closed[neighbor] closed neighbor 0 c2 = use[neighbor] = sorted_c.pop() c2 sorted_c.pop() sorted_c.pop sorted_c pop = use[neighbor] = sorted_c.pop() use[neighbor] use neighbor sorted_c.pop() c1 = closed[parent] c1 closed[parent] closed parent M += c2 M c2 q.append(neighbor) q.append q append neighbor print(M) print M print(*use) print *use use use = [0 for _ in range(N)] [0 for _ in range(N)] use b = map(int, input().split()) map(int, input().split()) b M += c2 c2 M b = a - 1, b - 1 b - 1 b parent = q.pop() q.pop() parent c = list(map(int, input().split())) list(map(int, input().split())) c q = [] [] q N = int(input()) int(input()) N M = 0 0 M closed = [0 for _ in range(N)] [0 for _ in range(N)] closed c2 = use[neighbor] = sorted_c.pop() sorted_c.pop() c2 sorted_c = sorted(c) sorted(c) sorted_c c1 = closed[parent] closed[parent] c1 neighbors = [[] for _ in range(N)] [[] for _ in range(N)] neighbors a, b = map(int, input().split()) map(int, input().split()) a a, b = a - 1, b - 1 a - 1 a
N = int(input())

neighbors = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    neighbors[a].append(b)
    neighbors[b].append(a)
c = list(map(int, input().split()))
sorted_c = sorted(c)

closed = [0 for _ in range(N)]
use = [0 for _ in range(N)]
q = []
q.append(0)
use[0] = sorted_c.pop()
M = 0


while len(q) > 0:
    parent = q.pop()
    closed[parent] = use[parent]
    for neighbor in neighbors[parent]:
        if closed[neighbor] == 0:
            c2 = use[neighbor] = sorted_c.pop()
            c1 = closed[parent]
            M += c2
            q.append(neighbor)

print(M)
print(*use)