import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
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 TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
ab = [LIST() for _ in range(N-1)]
c = sorted(LIST())
print(sum(c)-c[-1])

cnt = [0]*N
graph = [[] for _ in range(N)]

for a, b in ab:
	graph[a-1].append(b-1)
	graph[b-1].append(a-1)
	cnt[a-1] += 1
	cnt[b-1] += 1

ans = [0]*N

q = deque([0])
while q:
	p = q.popleft()
	ans[p] = c.pop()
	for i in graph[p]:
		if ans[i] == 0:
			q.append(i)

print(*ans) import sys, re sys re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache 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 def TUPLE(): return tuple(map(int, input().split())) TUPLE 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 = 10**6 INF 10**6 10 6 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 = sorted(LIST()) c sorted(LIST()) sorted LIST() LIST print(sum(c)-c[-1]) print sum(c)-c[-1] sum(c) sum c c[-1] c -1 cnt = [0]*N cnt [0]*N [0] 0 N [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] graph = [[] for _ in range(N)] graph [[] for _ in range(N)] for a, b in ab:
	graph[a-1].append(b-1)
	graph[b-1].append(a-1)
	cnt[a-1] += 1
	cnt[b-1] += 1 a b ab graph[a-1].append(b-1) [a-1].append [a-1] graph a-1 a 1 append b-1 b 1 graph[b-1].append(a-1) [b-1].append [b-1] graph b-1 b 1 append a-1 a 1 cnt[a-1] += 1 cnt[a-1] cnt a-1 a 1 1 cnt[b-1] += 1 cnt[b-1] cnt b-1 b 1 1 ans = [0]*N ans [0]*N [0] 0 N q = deque([0]) q deque([0]) deque [0] 0 while q:
	p = q.popleft()
	ans[p] = c.pop()
	for i in graph[p]:
		if ans[i] == 0:
			q.append(i) q p = q.popleft() p q.popleft() q.popleft q popleft ans[p] = c.pop() ans[p] ans p c.pop() c.pop c pop for i in graph[p]:
		if ans[i] == 0:
			q.append(i) i graph[p] graph p if ans[i] == 0:
			q.append(i) ans[i] == 0 ans[i] ans i 0 q.append(i) q.append q append i print(*ans) print *ans ans def TUPLE(): return tuple(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) TUPLE N = INT() INT() N INF = 10**6 10**6 INF cnt = [0]*N [0]*N cnt def ZIP(n): return zip(*(MAP() for _ in range(n))) def ZIP(n): return zip(*(MAP() for _ in range(n))) ZIP def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input mod = 10 ** 9 + 7 10 ** 9 + 7 mod graph = [[] for _ in range(N)] [[] for _ in range(N)] graph def INT(): return int(input()) def INT(): return int(input()) INT ans = [0]*N [0]*N ans q = deque([0]) deque([0]) q def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP def LIST(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) LIST c = sorted(LIST()) sorted(LIST()) c p = q.popleft() q.popleft() p ab = [LIST() for _ in range(N-1)] [LIST() for _ in range(N-1)] ab
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
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 TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
ab = [LIST() for _ in range(N-1)]
c = sorted(LIST())
print(sum(c)-c[-1])

cnt = [0]*N
graph = [[] for _ in range(N)]

for a, b in ab:
	graph[a-1].append(b-1)
	graph[b-1].append(a-1)
	cnt[a-1] += 1
	cnt[b-1] += 1

ans = [0]*N

q = deque([0])
while q:
	p = q.popleft()
	ans[p] = c.pop()
	for i in graph[p]:
		if ans[i] == 0:
			q.append(i)

print(*ans)