from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
import heapq
# https://atcoder.jp/contests/agc033/tasks/agc033_b
# B - LRUD Game
"""
"""
N = gi()
t = [[] for i in range(N + 5)]

for i in range(1, N):
    a = gi()
    b = gi()
    t[a].append(b)
    t[b].append(a)
cs = [0] * N
for i in range(N):
    cs[i] = gi()
cs.sort()
print(sum(cs) - max(cs))
vs = [0] * (N + 5)
ci = N - 1
q = deque()
q.append(1)

while len(q):
    v = q.pop()
    # print(v, ci)
    vs[v] = cs[ci]
    ci -= 1
    for u in t[v]:
        if vs[u]:
            continue
        else:
            q.append(u)
for i in range(1, N + 1):
    print("%d " % (vs[i]), end="") from _collections import deque from _ast import Num def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) parser while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) 1 data = list(input().split(' ')) data list(input().split(' ')) list input().split(' ') ().split () input split ' ' for number in data:
            if len(number) > 0:
                yield (number) number data if len(number) > 0:
                yield (number) len(number) > 0 len(number) len number 0 yield (number) number input_parser = parser() input_parser parser() parser def gw():
    global input_parser
    return next(input_parser) gw global input_parser return next(input_parser) next(input_parser) next input_parser def gi():
    data = gw()
    return int(data) gi data = gw() data gw() gw return int(data) int(data) int data MOD = int(1e9 + 7) MOD int(1e9 + 7) int 1e9 + 7 1e9 7 import numpy numpy from collections import deque from math import sqrt from math import floor import heapq heapq """
""" N = gi() N gi() gi [] for i in range(N + 5) for i in range(N + 5) i range(N + 5) range N + 5 N 5 for i in range(N + 5) [] t = [[] for i in range(N + 5)] t [[] for i in range(N + 5)] for i in range(1, N):
    a = gi()
    b = gi()
    t[a].append(b)
    t[b].append(a) i range(1, N) range 1 N a = gi() a gi() gi b = gi() b gi() gi t[a].append(b) [a].append [a] t a append b t[b].append(a) [b].append [b] t b append a cs = [0] * N cs [0] * N [0] 0 N for i in range(N):
    cs[i] = gi() i range(N) range N cs[i] = gi() cs[i] cs i gi() gi cs.sort() cs.sort cs sort print(sum(cs) - max(cs)) print sum(cs) - max(cs) sum(cs) sum cs max(cs) max cs vs = [0] * (N + 5) vs [0] * (N + 5) [0] 0 N + 5 N 5 ci = N - 1 ci N - 1 N 1 q = deque() q deque() deque q.append(1) q.append q append 1 while len(q):
    v = q.pop()
    # print(v, ci)
    vs[v] = cs[ci]
    ci -= 1
    for u in t[v]:
        if vs[u]:
            continue
        else:
            q.append(u) len(q) len q v = q.pop() v q.pop() q.pop q pop vs[v] = cs[ci] vs[v] vs v cs[ci] cs ci ci -= 1 ci 1 for u in t[v]:
        if vs[u]:
            continue
        else:
            q.append(u) u t[v] t v if vs[u]:
            continue
        else:
            q.append(u) vs[u] vs u continue q.append(u) q.append q append u for i in range(1, N + 1):
    print("%d " % (vs[i]), end="") i range(1, N + 1) range 1 N + 1 N 1 print("%d " % (vs[i]), end="") print "%d " % (vs[i]) "%d " vs[i] vs i end="" end "" ci -= 1 1 ci ci = N - 1 N - 1 ci input_parser = parser() parser() input_parser t = [[] for i in range(N + 5)] [[] for i in range(N + 5)] t b = gi() gi() b def gi():
    data = gw()
    return int(data) def gi():
    data = gw()
    return int(data) gi MOD = int(1e9 + 7) int(1e9 + 7) MOD N = gi() gi() N q = deque() deque() q vs = [0] * (N + 5) [0] * (N + 5) vs cs = [0] * N [0] * N cs def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) parser def gw():
    global input_parser
    return next(input_parser) def gw():
    global input_parser
    return next(input_parser) gw a = gi() gi() a v = q.pop() q.pop() v
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
import heapq
# https://atcoder.jp/contests/agc033/tasks/agc033_b
# B - LRUD Game
"""
"""
N = gi()
t = [[] for i in range(N + 5)]

for i in range(1, N):
    a = gi()
    b = gi()
    t[a].append(b)
    t[b].append(a)
cs = [0] * N
for i in range(N):
    cs[i] = gi()
cs.sort()
print(sum(cs) - max(cs))
vs = [0] * (N + 5)
ci = N - 1
q = deque()
q.append(1)

while len(q):
    v = q.pop()
    # print(v, ci)
    vs[v] = cs[ci]
    ci -= 1
    for u in t[v]:
        if vs[u]:
            continue
        else:
            q.append(u)
for i in range(1, N + 1):
    print("%d " % (vs[i]), end="")
