from heapq import heappush, heappop
from operator import itemgetter

# 入力
N = int(input())
a, b = (
    zip(*(map(int, input().split()) for _ in range(N - 1))) if N - 1 else
    ((), ())
)
c = list(map(int, input().split()))

# 頂点1を根とみなす。
# 頂点1から遠い頂点から順に小さい整数を書き込む
INF = 10**10
G = [{} for _ in range(N + 1)]
for x, y in zip(a, b):
    G[x][y] = 1
    G[y][x] = 1


def dijkstra(G, s):
    dp = [INF for _ in range(len(G))]
    q = []
    heappush(q, (0, s))
    while q:
        c, i = heappop(q)
        if dp[i] == INF:
            dp[i] = c
            for j, w in G[i].items():
                heappush(q, (c + w, j))
    return dp


dp = dijkstra(G, 1)
x = sorted(c)
ans = '{}\n{}'.format(
    sum(x[:-1]),
    ' '.join(
        str(d)
        for (_, _), d in sorted(
            zip(
                sorted(
                    enumerate(dp[1:]),
                    key=itemgetter(1),
                    reverse=True
                ),
                x
            )
        )
    )
)

# 出力
print(ans) from heapq import heappush, heappop from operator import itemgetter N = int(input()) N int(input()) int input() input map(int, input().split()) for _ in range(N - 1) for _ in range(N - 1) _ range(N - 1) range N - 1 N 1 for _ in range(N - 1) map(int, input().split()) map int input().split() ().split () input split a, b = (
    zip(*(map(int, input().split()) for _ in range(N - 1))) if N - 1 else
    ((), ())
) a zip(*(map(int, input().split()) for _ in range(N - 1))) if N - 1 else
    ((), ()) N - 1 N 1 zip(*(map(int, input().split()) for _ in range(N - 1))) zip *(map(int, input().split()) for _ in range(N - 1)) (map(int, input().split()) for _ in range(N - 1)) ((), ()) () () b c = list(map(int, input().split())) c list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split INF = 10**10 INF 10**10 10 10 {} for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) {} G = [{} for _ in range(N + 1)] G [{} for _ in range(N + 1)] for x, y in zip(a, b):
    G[x][y] = 1
    G[y][x] = 1 x y zip(a, b) zip a b G[x][y] = 1 G[x][y] [x] G x y 1 G[y][x] = 1 G[y][x] [y] G y x 1 def dijkstra(G, s):
    dp = [INF for _ in range(len(G))]
    q = []
    heappush(q, (0, s))
    while q:
        c, i = heappop(q)
        if dp[i] == INF:
            dp[i] = c
            for j, w in G[i].items():
                heappush(q, (c + w, j))
    return dp dijkstra INF for _ in range(len(G)) for _ in range(len(G)) _ range(len(G)) range len(G) len G for _ in range(len(G)) INF dp = [INF for _ in range(len(G))] dp [INF for _ in range(len(G))] q = [] q [] heappush(q, (0, s)) heappush q (0, s) 0 s while q:
        c, i = heappop(q)
        if dp[i] == INF:
            dp[i] = c
            for j, w in G[i].items():
                heappush(q, (c + w, j))
     q c, i = heappop(q) c heappop(q) heappop q i if dp[i] == INF:
            dp[i] = c
            for j, w in G[i].items():
                heappush(q, (c + w, j))
     dp[i] == INF dp[i] dp i INF dp[i] = c dp[i] dp i c for j, w in G[i].items():
                heappush(q, (c + w, j))
     j w G[i].items() [i].items [i] G i items heappush(q, (c + w, j)) heappush q (c + w, j) c + w c w j return dp dp G G s s dp = dijkstra(G, 1) dp dijkstra(G, 1) dijkstra G 1 x = sorted(c) x sorted(c) sorted c ans = '{}\n{}'.format(
    sum(x[:-1]),
    ' '.join(
        str(d)
        for (_, _), d in sorted(
            zip(
                sorted(
                    enumerate(dp[1:]),
                    key=itemgetter(1),
                    reverse=True
                ),
                x
            )
        )
    )
) ans '{}\n{}'.format(
    sum(x[:-1]),
    ' '.join(
        str(d)
        for (_, _), d in sorted(
            zip(
                sorted(
                    enumerate(dp[1:]),
                    key=itemgetter(1),
                    reverse=True
                ),
                x
            )
        )
    )
) '{}\n{}'.format '{}\n{}' format sum(x[:-1]) sum x[:-1] x :-1 -1 ' '.join(
        str(d)
        for (_, _), d in sorted(
            zip(
                sorted(
                    enumerate(dp[1:]),
                    key=itemgetter(1),
                    reverse=True
                ),
                x
            )
        )
    ) ' '.join ' ' join str(d) str d print(ans) print ans ans = '{}\n{}'.format(
    sum(x[:-1]),
    ' '.join(
        str(d)
        for (_, _), d in sorted(
            zip(
                sorted(
                    enumerate(dp[1:]),
                    key=itemgetter(1),
                    reverse=True
                ),
                x
            )
        )
    )
) '{}\n{}'.format(
    sum(x[:-1]),
    ' '.join(
        str(d)
        for (_, _), d in sorted(
            zip(
                sorted(
                    enumerate(dp[1:]),
                    key=itemgetter(1),
                    reverse=True
                ),
                x
            )
        )
    )
) ans G = [{} for _ in range(N + 1)] [{} for _ in range(N + 1)] G N = int(input()) int(input()) N b = (
    zip(*(map(int, input().split()) for _ in range(N - 1))) if N - 1 else
    ((), ())
) zip(*(map(int, input().split()) for _ in range(N - 1))) if N - 1 else
    ((), ()) b INF = 10**10 10**10 INF dp = dijkstra(G, 1) dijkstra(G, 1) dp x = sorted(c) sorted(c) x a, b = (
    zip(*(map(int, input().split()) for _ in range(N - 1))) if N - 1 else
    ((), ())
) zip(*(map(int, input().split()) for _ in range(N - 1))) if N - 1 else
    ((), ()) a c = list(map(int, input().split())) list(map(int, input().split())) c def dijkstra(G, s):
    dp = [INF for _ in range(len(G))]
    q = []
    heappush(q, (0, s))
    while q:
        c, i = heappop(q)
        if dp[i] == INF:
            dp[i] = c
            for j, w in G[i].items():
                heappush(q, (c + w, j))
    return dp def dijkstra(G, s):
    dp = [INF for _ in range(len(G))]
    q = []
    heappush(q, (0, s))
    while q:
        c, i = heappop(q)
        if dp[i] == INF:
            dp[i] = c
            for j, w in G[i].items():
                heappush(q, (c + w, j))
    return dp dijkstra
from heapq import heappush, heappop
from operator import itemgetter

# 入力
N = int(input())
a, b = (
    zip(*(map(int, input().split()) for _ in range(N - 1))) if N - 1 else
    ((), ())
)
c = list(map(int, input().split()))

# 頂点1を根とみなす。
# 頂点1から遠い頂点から順に小さい整数を書き込む
INF = 10**10
G = [{} for _ in range(N + 1)]
for x, y in zip(a, b):
    G[x][y] = 1
    G[y][x] = 1


def dijkstra(G, s):
    dp = [INF for _ in range(len(G))]
    q = []
    heappush(q, (0, s))
    while q:
        c, i = heappop(q)
        if dp[i] == INF:
            dp[i] = c
            for j, w in G[i].items():
                heappush(q, (c + w, j))
    return dp


dp = dijkstra(G, 1)
x = sorted(c)
ans = '{}\n{}'.format(
    sum(x[:-1]),
    ' '.join(
        str(d)
        for (_, _), d in sorted(
            zip(
                sorted(
                    enumerate(dp[1:]),
                    key=itemgetter(1),
                    reverse=True
                ),
                x
            )
        )
    )
)

# 出力
print(ans)
