import sys
readline = sys.stdin.readline
write = sys.stdout.write

N = int(input())
edges = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int,readline().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
C = list(map(int, readline().split()))
C.sort()
print(str(sum(C)-C[-1]))

queue = [0]
D = ["x" for i in range(N)]
while queue:
    op = queue.pop(0)
    if D[op] != "x":
        continue
    D[op] = str(C.pop(-1))
    numchild = len(edges[op])
    for i in range(numchild):
        queue.append(edges[op][i])
print((' '.join(D))) import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline write = sys.stdout.write write sys.stdout.write sys.stdout sys stdout write N = int(input()) N int(input()) int input() input [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] edges = [[] for i in range(N)] edges [[] for i in range(N)] for i in range(N-1):
    a, b = map(int,readline().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1) i range(N-1) range N-1 N 1 a, b = map(int,readline().split()) a map(int,readline().split()) map int readline().split() ().split () readline split b edges[a-1].append(b-1) [a-1].append [a-1] edges a-1 a 1 append b-1 b 1 edges[b-1].append(a-1) [b-1].append [b-1] edges b-1 b 1 append a-1 a 1 C = list(map(int, readline().split())) C list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split C.sort() C.sort C sort print(str(sum(C)-C[-1])) print str(sum(C)-C[-1]) str sum(C)-C[-1] sum(C) sum C C[-1] C -1 queue = [0] queue [0] 0 "x" for i in range(N) for i in range(N) i range(N) range N for i in range(N) "x" D = ["x" for i in range(N)] D ["x" for i in range(N)] while queue:
    op = queue.pop(0)
    if D[op] != "x":
        continue
    D[op] = str(C.pop(-1))
    numchild = len(edges[op])
    for i in range(numchild):
        queue.append(edges[op][i]) queue op = queue.pop(0) op queue.pop(0) queue.pop queue pop 0 if D[op] != "x":
        continue
     D[op] != "x" D[op] D op "x" continue D[op] = str(C.pop(-1)) D[op] D op str(C.pop(-1)) str C.pop(-1) C.pop C pop -1 numchild = len(edges[op]) numchild len(edges[op]) len edges[op] edges op for i in range(numchild):
        queue.append(edges[op][i]) i range(numchild) range numchild queue.append(edges[op][i]) queue.append queue append edges[op][i] [op] edges op i print((' '.join(D))) print ' '.join(D) ' '.join ' ' join D N = int(input()) int(input()) N readline = sys.stdin.readline sys.stdin.readline readline C = list(map(int, readline().split())) list(map(int, readline().split())) C a, b = map(int,readline().split()) map(int,readline().split()) a write = sys.stdout.write sys.stdout.write write D = ["x" for i in range(N)] ["x" for i in range(N)] D op = queue.pop(0) queue.pop(0) op numchild = len(edges[op]) len(edges[op]) numchild b = map(int,readline().split()) map(int,readline().split()) b queue = [0] [0] queue edges = [[] for i in range(N)] [[] for i in range(N)] edges
import sys
readline = sys.stdin.readline
write = sys.stdout.write

N = int(input())
edges = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int,readline().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
C = list(map(int, readline().split()))
C.sort()
print(str(sum(C)-C[-1]))

queue = [0]
D = ["x" for i in range(N)]
while queue:
    op = queue.pop(0)
    if D[op] != "x":
        continue
    D[op] = str(C.pop(-1))
    numchild = len(edges[op])
    for i in range(numchild):
        queue.append(edges[op][i])
print((' '.join(D)))