from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n = I()
G = [[] for _ in range(n)]
for a, b in LIR(n - 1):
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]


C = sorted(LI())
ans = [0] * n
ans[0] = C.pop()
total = sum(C)
dq = deque([0])
while dq:
    u = dq.popleft()
    for v in G[u]:
        if not ans[v]:
            ans[v] = C.pop()
            dq += [v]


print(total)
print(*ans)



 from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math math import bisect bisect import random random from itertools import permutations, accumulate, combinations, product import sys sys import string string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) sys.setrecursionlimit sys setrecursionlimit 2147483647 INF = 10 ** 20 INF 10 ** 20 10 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) LI def I(): return int(sys.stdin.buffer.readline()) I def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() LS def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') S I() for i in range(n) for i in range(n) i range(n) range n for i in range(n) I() I def IR(n): return [I() for i in range(n)] IR n n LI() for i in range(n) for i in range(n) i range(n) range n for i in range(n) LI() LI def LIR(n): return [LI() for i in range(n)] LIR n n S() for i in range(n) for i in range(n) i range(n) range n for i in range(n) S() S def SR(n): return [S() for i in range(n)] SR n n LS() for i in range(n) for i in range(n) i range(n) range n for i in range(n) LS() LS def LSR(n): return [LS() for i in range(n)] LSR n n list(S()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) list(S()) list S() S def SRL(n): return [list(S()) for i in range(n)] SRL n n [int(j) for j in list(S())] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [int(j) for j in list(S())] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] MSRL n n mod = 1000000007 mod 1000000007 n = I() n I() I [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] G = [[] for _ in range(n)] G [[] for _ in range(n)] for a, b in LIR(n - 1):
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1] a b LIR(n - 1) LIR n - 1 n 1 G[a - 1] += [b - 1] G[a - 1] G a - 1 a 1 [b - 1] b - 1 b 1 G[b - 1] += [a - 1] G[b - 1] G b - 1 b 1 [a - 1] a - 1 a 1 C = sorted(LI()) C sorted(LI()) sorted LI() LI ans = [0] * n ans [0] * n [0] 0 n ans[0] = C.pop() ans[0] ans 0 C.pop() C.pop C pop total = sum(C) total sum(C) sum C dq = deque([0]) dq deque([0]) deque [0] 0 while dq:
    u = dq.popleft()
    for v in G[u]:
        if not ans[v]:
            ans[v] = C.pop()
            dq += [v] dq u = dq.popleft() u dq.popleft() dq.popleft dq popleft for v in G[u]:
        if not ans[v]:
            ans[v] = C.pop()
            dq += [v] v G[u] G u if not ans[v]:
            ans[v] = C.pop()
            dq += [v] not ans[v] ans[v] ans v ans[v] = C.pop() ans[v] ans v C.pop() C.pop C pop dq += [v] dq [v] v print(total) print total print(*ans) print *ans ans def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() LS def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) LI def SR(n): return [S() for i in range(n)] def SR(n): return [S() for i in range(n)] SR G = [[] for _ in range(n)] [[] for _ in range(n)] G C = sorted(LI()) sorted(LI()) C n = I() I() n ans = [0] * n [0] * n ans dq = deque([0]) deque([0]) dq INF = 10 ** 20 10 ** 20 INF dq += [v] [v] dq u = dq.popleft() dq.popleft() u def SRL(n): return [list(S()) for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] SRL mod = 1000000007 1000000007 mod total = sum(C) sum(C) total def I(): return int(sys.stdin.buffer.readline()) def I(): return int(sys.stdin.buffer.readline()) I def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') S def LIR(n): return [LI() for i in range(n)] def LIR(n): return [LI() for i in range(n)] LIR def LSR(n): return [LS() for i in range(n)] def LSR(n): return [LS() for i in range(n)] LSR def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] MSRL def IR(n): return [I() for i in range(n)] def IR(n): return [I() for i in range(n)] IR
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n = I()
G = [[] for _ in range(n)]
for a, b in LIR(n - 1):
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]


C = sorted(LI())
ans = [0] * n
ans[0] = C.pop()
total = sum(C)
dq = deque([0])
while dq:
    u = dq.popleft()
    for v in G[u]:
        if not ans[v]:
            ans[v] = C.pop()
            dq += [v]


print(total)
print(*ans)




