n, *L = map(int, open(0).read().split())
ab = L[:2 * n - 2]
c = sorted(L[2 * n - 2:])
con = [[] for _ in range(n)]
ans = [0] * n
tot = sum(c) - max(c)
for a, b in zip(*[iter(ab)] * 2):
	con[a - 1].append(b - 1)
	con[b - 1].append(a - 1)
vis = [0] * n
q = [0]
vis[0] = 1
while q:
	cur = q.pop()
	ans[cur] = c.pop()
	for nxt in con[cur]:
		if vis[nxt]:
			continue
		q.append(nxt)
		vis[nxt] = 1
print(tot)
print(*ans) n, *L = map(int, open(0).read().split()) n map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split *L L ab = L[:2 * n - 2] ab L[:2 * n - 2] L :2 * n - 2 2 * n - 2 2 * n 2 n 2 c = sorted(L[2 * n - 2:]) c sorted(L[2 * n - 2:]) sorted L[2 * n - 2:] L 2 * n - 2: 2 * n - 2 2 * n 2 n 2 [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] con = [[] for _ in range(n)] con [[] for _ in range(n)] ans = [0] * n ans [0] * n [0] 0 n tot = sum(c) - max(c) tot sum(c) - max(c) sum(c) sum c max(c) max c for a, b in zip(*[iter(ab)] * 2):
	con[a - 1].append(b - 1)
	con[b - 1].append(a - 1) a b zip(*[iter(ab)] * 2) zip *[iter(ab)] * 2 [iter(ab)] * 2 [iter(ab)] iter(ab) iter ab 2 con[a - 1].append(b - 1) [a - 1].append [a - 1] con a - 1 a 1 append b - 1 b 1 con[b - 1].append(a - 1) [b - 1].append [b - 1] con b - 1 b 1 append a - 1 a 1 vis = [0] * n vis [0] * n [0] 0 n q = [0] q [0] 0 vis[0] = 1 vis[0] vis 0 1 while q:
	cur = q.pop()
	ans[cur] = c.pop()
	for nxt in con[cur]:
		if vis[nxt]:
			continue
		q.append(nxt)
		vis[nxt] = 1 q cur = q.pop() cur q.pop() q.pop q pop ans[cur] = c.pop() ans[cur] ans cur c.pop() c.pop c pop for nxt in con[cur]:
		if vis[nxt]:
			continue
		q.append(nxt)
		vis[nxt] = 1 nxt con[cur] con cur if vis[nxt]:
			continue
		 vis[nxt] vis nxt continue q.append(nxt) q.append q append nxt vis[nxt] = 1 vis[nxt] vis nxt 1 print(tot) print tot print(*ans) print *ans ans cur = q.pop() q.pop() cur q = [0] [0] q ans = [0] * n [0] * n ans con = [[] for _ in range(n)] [[] for _ in range(n)] con vis = [0] * n [0] * n vis ab = L[:2 * n - 2] L[:2 * n - 2] ab tot = sum(c) - max(c) sum(c) - max(c) tot n, *L = map(int, open(0).read().split()) map(int, open(0).read().split()) n c = sorted(L[2 * n - 2:]) sorted(L[2 * n - 2:]) c
n, *L = map(int, open(0).read().split())
ab = L[:2 * n - 2]
c = sorted(L[2 * n - 2:])
con = [[] for _ in range(n)]
ans = [0] * n
tot = sum(c) - max(c)
for a, b in zip(*[iter(ab)] * 2):
	con[a - 1].append(b - 1)
	con[b - 1].append(a - 1)
vis = [0] * n
q = [0]
vis[0] = 1
while q:
	cur = q.pop()
	ans[cur] = c.pop()
	for nxt in con[cur]:
		if vis[nxt]:
			continue
		q.append(nxt)
		vis[nxt] = 1
print(tot)
print(*ans)
