n = int(input())
route = [[] for i in range(n)] #どの木と隣接か
for i in range(n-1):
	a,b = (x-1 for x in map(int,input().split()))
	route[a]+=[b]
	route[b]+=[a]
c = list(map(int,input().split()))
c.sort(reverse=1)

check = [False]*n #check済みか否か
ans = [0]*n #cを入れてく
cnt = 0 #何個目を見てるか、cに使う
q = [0]
# print(route)
while q:
	cur = q[0] #今どこの木を見てるか
	q = q[1:]
	check[cur] = True
	ans[cur] = c[cnt]
	cnt += 1
	for r in route[cur]:
		if check[r]:
			continue
		q.append(r)
print(sum(ans[1:]))
print(*ans) n = int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] route = [[] for i in range(n)] route [[] for i in range(n)] for i in range(n-1):
	a,b = (x-1 for x in map(int,input().split()))
	route[a]+=[b]
	route[b]+=[a] i range(n-1) range n-1 n 1 x-1 for x in map(int,input().split()) for x in map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split for x in map(int,input().split()) x-1 x 1 a,b = (x-1 for x in map(int,input().split())) a (x-1 for x in map(int,input().split())) b route[a]+=[b] route[a] route a [b] b route[b]+=[a] route[b] route b [a] a c = list(map(int,input().split())) c list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split c.sort(reverse=1) c.sort c sort reverse=1 reverse 1 check = [False]*n check [False]*n [False] False n ans = [0]*n ans [0]*n [0] 0 n cnt = 0 cnt 0 q = [0] q [0] 0 while q:
	cur = q[0] #今どこの木を見てるか
	q = q[1:]
	check[cur] = True
	ans[cur] = c[cnt]
	cnt += 1
	for r in route[cur]:
		if check[r]:
			continue
		q.append(r) q cur = q[0] cur q[0] q 0 q = q[1:] q q[1:] q 1: 1 check[cur] = True check[cur] check cur True ans[cur] = c[cnt] ans[cur] ans cur c[cnt] c cnt cnt += 1 cnt 1 for r in route[cur]:
		if check[r]:
			continue
		q.append(r) r route[cur] route cur if check[r]:
			continue
		 check[r] check r continue q.append(r) q.append q append r print(sum(ans[1:])) print sum(ans[1:]) sum ans[1:] ans 1: 1 print(*ans) print *ans ans c = list(map(int,input().split())) list(map(int,input().split())) c check = [False]*n [False]*n check q = q[1:] q[1:] q a,b = (x-1 for x in map(int,input().split())) (x-1 for x in map(int,input().split())) a n = int(input()) int(input()) n ans = [0]*n [0]*n ans cnt = 0 0 cnt cur = q[0] q[0] cur route = [[] for i in range(n)] [[] for i in range(n)] route b = (x-1 for x in map(int,input().split())) (x-1 for x in map(int,input().split())) b q = [0] [0] q cnt += 1 1 cnt
n = int(input())
route = [[] for i in range(n)] #どの木と隣接か
for i in range(n-1):
	a,b = (x-1 for x in map(int,input().split()))
	route[a]+=[b]
	route[b]+=[a]
c = list(map(int,input().split()))
c.sort(reverse=1)

check = [False]*n #check済みか否か
ans = [0]*n #cを入れてく
cnt = 0 #何個目を見てるか、cに使う
q = [0]
# print(route)
while q:
	cur = q[0] #今どこの木を見てるか
	q = q[1:]
	check[cur] = True
	ans[cur] = c[cnt]
	cnt += 1
	for r in route[cur]:
		if check[r]:
			continue
		q.append(r)
print(sum(ans[1:]))
print(*ans)