import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
ab = [LIST() for _ in range(N-1)]
c = LIST()
c.sort(reverse=True)
tree = [[] for _ in range(N)]
for a, b in ab:
	tree[a-1].append(b-1)
	tree[b-1].append(a-1)

start=None
for i in range(N):
	if len(tree[i]) == 1:
		start = i
		break

ans = [0]*N
q = deque()
q.append(start)
ans[start] = c[0]
cnt = 1
while q:
	n = q.popleft()
	for node in tree[n]:
		if ans[node]:
			continue
		ans[node] = c[cnt]
		cnt += 1
		q.append(node)
print(sum(c)-max(c))
print(*ans) import sys, re sys re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() input def INT(): return int(input()) INT def MAP(): return map(int, input().split()) MAP def LIST(): return list(map(int, input().split())) LIST MAP() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) MAP() MAP def ZIP(n): return zip(*(MAP() for _ in range(n))) ZIP n n sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = float('inf') INF float('inf') float 'inf' mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 N = INT() N INT() INT LIST() for _ in range(N-1) for _ in range(N-1) _ range(N-1) range N-1 N 1 for _ in range(N-1) LIST() LIST ab = [LIST() for _ in range(N-1)] ab [LIST() for _ in range(N-1)] c = LIST() c LIST() LIST c.sort(reverse=True) c.sort c sort reverse=True reverse True [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] tree = [[] for _ in range(N)] tree [[] for _ in range(N)] for a, b in ab:
	tree[a-1].append(b-1)
	tree[b-1].append(a-1) a b ab tree[a-1].append(b-1) [a-1].append [a-1] tree a-1 a 1 append b-1 b 1 tree[b-1].append(a-1) [b-1].append [b-1] tree b-1 b 1 append a-1 a 1 start=None start None for i in range(N):
	if len(tree[i]) == 1:
		start = i
		break i range(N) range N if len(tree[i]) == 1:
		start = i
		break len(tree[i]) == 1 len(tree[i]) len tree[i] tree i 1 start = i start i break ans = [0]*N ans [0]*N [0] 0 N q = deque() q deque() deque q.append(start) q.append q append start ans[start] = c[0] ans[start] ans start c[0] c 0 cnt = 1 cnt 1 while q:
	n = q.popleft()
	for node in tree[n]:
		if ans[node]:
			continue
		ans[node] = c[cnt]
		cnt += 1
		q.append(node) q n = q.popleft() n q.popleft() q.popleft q popleft for node in tree[n]:
		if ans[node]:
			continue
		ans[node] = c[cnt]
		cnt += 1
		q.append(node) node tree[n] tree n if ans[node]:
			continue
		 ans[node] ans node continue ans[node] = c[cnt] ans[node] ans node c[cnt] c cnt cnt += 1 cnt 1 q.append(node) q.append q append node print(sum(c)-max(c)) print sum(c)-max(c) sum(c) sum c max(c) max c print(*ans) print *ans ans def ZIP(n): return zip(*(MAP() for _ in range(n))) def ZIP(n): return zip(*(MAP() for _ in range(n))) ZIP cnt = 1 1 cnt n = q.popleft() q.popleft() n def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP INF = float('inf') float('inf') INF def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input q = deque() deque() q c = LIST() LIST() c tree = [[] for _ in range(N)] [[] for _ in range(N)] tree start=None None start def INT(): return int(input()) def INT(): return int(input()) INT start = i i start def LIST(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) LIST mod = 10 ** 9 + 7 10 ** 9 + 7 mod ab = [LIST() for _ in range(N-1)] [LIST() for _ in range(N-1)] ab cnt += 1 1 cnt N = INT() INT() N ans = [0]*N [0]*N ans
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
ab = [LIST() for _ in range(N-1)]
c = LIST()
c.sort(reverse=True)
tree = [[] for _ in range(N)]
for a, b in ab:
	tree[a-1].append(b-1)
	tree[b-1].append(a-1)

start=None
for i in range(N):
	if len(tree[i]) == 1:
		start = i
		break

ans = [0]*N
q = deque()
q.append(start)
ans[start] = c[0]
cnt = 1
while q:
	n = q.popleft()
	for node in tree[n]:
		if ans[node]:
			continue
		ans[node] = c[cnt]
		cnt += 1
		q.append(node)
print(sum(c)-max(c))
print(*ans)
