import sys
from collections import deque
sys.setrecursionlimit(10**9)

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]
C = list(map(int, input().split()))

score = sum(C) - max(C)
C.sort(reverse=True)
C = deque(C)
con = [[] for _ in range(N + 1)]
ans = [0 for i in range(N + 1)]

for ab in AB:
    a, b = ab
    con[a].append(b)
    con[b].append(a)


def dfs(x):
    if len(C) == 0:
        return
    if ans[x] == 0:
        ans[x] = C[0]
        C.popleft()
        for c in con[x]:
            dfs(c)


dfs(1)
ans = list(map(str, ans))
print(score)
print(' '.join(ans[1:])) import sys sys from collections import deque sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 N = int(input()) N int(input()) int input() input list(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) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split AB = [list(map(int, input().split())) for _ in range(N - 1)] AB [list(map(int, input().split())) for _ in range(N - 1)] C = list(map(int, input().split())) C list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split score = sum(C) - max(C) score sum(C) - max(C) sum(C) sum C max(C) max C C.sort(reverse=True) C.sort C sort reverse=True reverse True C = deque(C) C deque(C) deque C [] for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [] con = [[] for _ in range(N + 1)] con [[] for _ in range(N + 1)] 0 for i in range(N + 1) for i in range(N + 1) i range(N + 1) range N + 1 N 1 for i in range(N + 1) 0 ans = [0 for i in range(N + 1)] ans [0 for i in range(N + 1)] for ab in AB:
    a, b = ab
    con[a].append(b)
    con[b].append(a) ab AB a, b = ab a ab b con[a].append(b) [a].append [a] con a append b con[b].append(a) [b].append [b] con b append a def dfs(x):
    if len(C) == 0:
        return
    if ans[x] == 0:
        ans[x] = C[0]
        C.popleft()
        for c in con[x]:
            dfs(c) dfs if len(C) == 0:
        return
     len(C) == 0 len(C) len C 0 return if ans[x] == 0:
        ans[x] = C[0]
        C.popleft()
        for c in con[x]:
            dfs(c) ans[x] == 0 ans[x] ans x 0 ans[x] = C[0] ans[x] ans x C[0] C 0 C.popleft() C.popleft C popleft for c in con[x]:
            dfs(c) c con[x] con x dfs(c) dfs c x x dfs(1) dfs 1 ans = list(map(str, ans)) ans list(map(str, ans)) list map(str, ans) map str ans print(score) print score print(' '.join(ans[1:])) print ' '.join(ans[1:]) ' '.join ' ' join ans[1:] ans 1: 1 C = list(map(int, input().split())) list(map(int, input().split())) C ans = list(map(str, ans)) list(map(str, ans)) ans C = deque(C) deque(C) C b = ab ab b ans = [0 for i in range(N + 1)] [0 for i in range(N + 1)] ans AB = [list(map(int, input().split())) for _ in range(N - 1)] [list(map(int, input().split())) for _ in range(N - 1)] AB con = [[] for _ in range(N + 1)] [[] for _ in range(N + 1)] con score = sum(C) - max(C) sum(C) - max(C) score N = int(input()) int(input()) N a, b = ab ab a def dfs(x):
    if len(C) == 0:
        return
    if ans[x] == 0:
        ans[x] = C[0]
        C.popleft()
        for c in con[x]:
            dfs(c) def dfs(x):
    if len(C) == 0:
        return
    if ans[x] == 0:
        ans[x] = C[0]
        C.popleft()
        for c in con[x]:
            dfs(c) dfs
import sys
from collections import deque
sys.setrecursionlimit(10**9)

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]
C = list(map(int, input().split()))

score = sum(C) - max(C)
C.sort(reverse=True)
C = deque(C)
con = [[] for _ in range(N + 1)]
ans = [0 for i in range(N + 1)]

for ab in AB:
    a, b = ab
    con[a].append(b)
    con[b].append(a)


def dfs(x):
    if len(C) == 0:
        return
    if ans[x] == 0:
        ans[x] = C[0]
        C.popleft()
        for c in con[x]:
            dfs(c)


dfs(1)
ans = list(map(str, ans))
print(score)
print(' '.join(ans[1:]))
