#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
E = [[] for i in range(N + 1)]

for i in range(N - 1):
	a, b = map(int, raw_input().split())
	E[a].append(b)
	E[b].append(a)

c = map(int, raw_input().split())
c.sort(reverse = True)
print sum(c[1:])

ans = [0] * (N + 1)
def func(pos, pre, id):
	ans[pos] = c[id]
	id += 1
	for to in E[pos]:
		if to != pre:
			id = func(to, pos, id)
	return id

func(1, -1, 0)
print " ".join(map(str, ans[1:])) from collections import deque import itertools as ite itertools import sys sys import math math sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 INF = 10 ** 18 INF 10 ** 18 10 18 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 N = input() N input() input [] 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) [] E = [[] for i in range(N + 1)] E [[] for i in range(N + 1)] for i in range(N - 1):
	a, b = map(int, raw_input().split())
	E[a].append(b)
	E[b].append(a) i range(N - 1) range N - 1 N 1 a, b = map(int, raw_input().split()) a map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split b E[a].append(b) [a].append [a] E a append b E[b].append(a) [b].append [b] E b append a c = map(int, raw_input().split()) c map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split c.sort(reverse = True) c.sort c sort reverse = True reverse True print sum(c[1:]) sum c[1:] c 1: 1 ans = [0] * (N + 1) ans [0] * (N + 1) [0] 0 N + 1 N 1 def func(pos, pre, id):
	ans[pos] = c[id]
	id += 1
	for to in E[pos]:
		if to != pre:
			id = func(to, pos, id)
	return id func ans[pos] = c[id] ans[pos] ans pos c[id] c id id += 1 id 1 for to in E[pos]:
		if to != pre:
			id = func(to, pos, id)
	 to E[pos] E pos if to != pre:
			id = func(to, pos, id)
	 to != pre to pre id = func(to, pos, id) id func(to, pos, id) func to pos id return id id pos pos pre pre id id func(1, -1, 0) func 1 -1 0 print " ".join(map(str, ans[1:])) " ".join " " join map(str, ans[1:]) map str ans[1:] ans 1: 1 N = input() input() N def func(pos, pre, id):
	ans[pos] = c[id]
	id += 1
	for to in E[pos]:
		if to != pre:
			id = func(to, pos, id)
	return id def func(pos, pre, id):
	ans[pos] = c[id]
	id += 1
	for to in E[pos]:
		if to != pre:
			id = func(to, pos, id)
	return id func E = [[] for i in range(N + 1)] [[] for i in range(N + 1)] E MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD ans = [0] * (N + 1) [0] * (N + 1) ans a, b = map(int, raw_input().split()) map(int, raw_input().split()) a INF = 10 ** 18 10 ** 18 INF b = map(int, raw_input().split()) map(int, raw_input().split()) b c = map(int, raw_input().split()) map(int, raw_input().split()) c
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
E = [[] for i in range(N + 1)]

for i in range(N - 1):
	a, b = map(int, raw_input().split())
	E[a].append(b)
	E[b].append(a)

c = map(int, raw_input().split())
c.sort(reverse = True)
print sum(c[1:])

ans = [0] * (N + 1)
def func(pos, pre, id):
	ans[pos] = c[id]
	id += 1
	for to in E[pos]:
		if to != pre:
			id = func(to, pos, id)
	return id

func(1, -1, 0)
print " ".join(map(str, ans[1:]))