*D, = open(0)
n = int(D[0])

edge = [[] for _ in range(n+1)]
v_val = [0 for _ in range(n+1)]

dist = {}

for i in range(1, n):
    a, b = map(int, D[i].split())
    edge[a].append(b)
    edge[b].append(a)
c = list(map(int, D[n].split()))
c = sorted(c, reverse=True)

from collections import deque
visited = [False for _ in range(len(edge))]
start = 1
que = deque()
que.append(start)
order = []
order.append(start)
visited[start] = True

while que:
    node = que.popleft()
    for it in edge[node]:
        if not visited[it]:
            order.append(it)
            visited[it] = True
            que.append(it)
# calculate cost
v_val = [0 for _ in range(len(c)+1)]
for i, it in enumerate(order):
    v_val[it] = c[i]

print(sum(c[1:]))
print(' '.join(map(str, v_val[1:]))) *D, = open(0) *D D open(0) open 0 n = int(D[0]) n int(D[0]) int D[0] D 0 [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] edge = [[] for _ in range(n+1)] edge [[] for _ in range(n+1)] 0 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) 0 v_val = [0 for _ in range(n+1)] v_val [0 for _ in range(n+1)] dist = {} dist {} for i in range(1, n):
    a, b = map(int, D[i].split())
    edge[a].append(b)
    edge[b].append(a) i range(1, n) range 1 n a, b = map(int, D[i].split()) a map(int, D[i].split()) map int D[i].split() [i].split [i] D i split b edge[a].append(b) [a].append [a] edge a append b edge[b].append(a) [b].append [b] edge b append a c = list(map(int, D[n].split())) c list(map(int, D[n].split())) list map(int, D[n].split()) map int D[n].split() [n].split [n] D n split c = sorted(c, reverse=True) c sorted(c, reverse=True) sorted c reverse=True reverse True from collections import deque False for _ in range(len(edge)) for _ in range(len(edge)) _ range(len(edge)) range len(edge) len edge for _ in range(len(edge)) False visited = [False for _ in range(len(edge))] visited [False for _ in range(len(edge))] start = 1 start 1 que = deque() que deque() deque que.append(start) que.append que append start order = [] order [] order.append(start) order.append order append start visited[start] = True visited[start] visited start True while que:
    node = que.popleft()
    for it in edge[node]:
        if not visited[it]:
            order.append(it)
            visited[it] = True
            que.append(it)
# calculate cost que node = que.popleft() node que.popleft() que.popleft que popleft for it in edge[node]:
        if not visited[it]:
            order.append(it)
            visited[it] = True
            que.append(it)
# calculate cost it edge[node] edge node if not visited[it]:
            order.append(it)
            visited[it] = True
            que.append(it)
# calculate cost not visited[it] visited[it] visited it order.append(it) order.append order append it visited[it] = True visited[it] visited it True que.append(it) que.append que append it 0 for _ in range(len(c)+1) for _ in range(len(c)+1) _ range(len(c)+1) range len(c)+1 len(c) len c 1 for _ in range(len(c)+1) 0 v_val = [0 for _ in range(len(c)+1)] v_val [0 for _ in range(len(c)+1)] for i, it in enumerate(order):
    v_val[it] = c[i] i it enumerate(order) enumerate order v_val[it] = c[i] v_val[it] v_val it c[i] c i print(sum(c[1:])) print sum(c[1:]) sum c[1:] c 1: 1 print(' '.join(map(str, v_val[1:]))) print ' '.join(map(str, v_val[1:])) ' '.join ' ' join map(str, v_val[1:]) map str v_val[1:] v_val 1: 1 order = [] [] order start = 1 1 start n = int(D[0]) int(D[0]) n c = sorted(c, reverse=True) sorted(c, reverse=True) c b = map(int, D[i].split()) map(int, D[i].split()) b visited = [False for _ in range(len(edge))] [False for _ in range(len(edge))] visited que = deque() deque() que c = list(map(int, D[n].split())) list(map(int, D[n].split())) c edge = [[] for _ in range(n+1)] [[] for _ in range(n+1)] edge v_val = [0 for _ in range(n+1)] [0 for _ in range(n+1)] v_val a, b = map(int, D[i].split()) map(int, D[i].split()) a dist = {} {} dist v_val = [0 for _ in range(len(c)+1)] [0 for _ in range(len(c)+1)] v_val node = que.popleft() que.popleft() node
*D, = open(0)
n = int(D[0])

edge = [[] for _ in range(n+1)]
v_val = [0 for _ in range(n+1)]

dist = {}

for i in range(1, n):
    a, b = map(int, D[i].split())
    edge[a].append(b)
    edge[b].append(a)
c = list(map(int, D[n].split()))
c = sorted(c, reverse=True)

from collections import deque
visited = [False for _ in range(len(edge))]
start = 1
que = deque()
que.append(start)
order = []
order.append(start)
visited[start] = True

while que:
    node = que.popleft()
    for it in edge[node]:
        if not visited[it]:
            order.append(it)
            visited[it] = True
            que.append(it)
# calculate cost
v_val = [0 for _ in range(len(c)+1)]
for i, it in enumerate(order):
    v_val[it] = c[i]

print(sum(c[1:]))
print(' '.join(map(str, v_val[1:])))