import heapq
from collections import deque
n = int(input())
graph = [set() for _ in range(n)]

for _ in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    graph[a].add(b)
    graph[b].add(a)

nodes = [False for _ in range(n)]
values = list(map(lambda x: -int(x), input().split()))
print(-sum(values) + min(values))

heapq.heapify(values)
next_nodes = deque()
next_nodes.append(0)
while next_nodes:
    node = next_nodes.popleft()
    nodes[node] = -heapq.heappop(values)
    for g in graph[node]:
        if not (nodes[g]):
            next_nodes.append(g)

print(*nodes) import heapq heapq from collections import deque n = int(input()) n int(input()) int input() input set() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) set() set graph = [set() for _ in range(n)] graph [set() for _ in range(n)] for _ in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    graph[a].add(b)
    graph[b].add(a) _ range(n - 1) range n - 1 n 1 a, b = map(lambda x: int(x) - 1, input().split()) a map(lambda x: int(x) - 1, input().split()) map lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x input().split() ().split () input split b graph[a].add(b) [a].add [a] graph a add b graph[b].add(a) [b].add [b] graph b add a False for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) False nodes = [False for _ in range(n)] nodes [False for _ in range(n)] values = list(map(lambda x: -int(x), input().split())) values list(map(lambda x: -int(x), input().split())) list map(lambda x: -int(x), input().split()) map lambda x: -int(x) -int(x) int(x) int x x input().split() ().split () input split print(-sum(values) + min(values)) print -sum(values) + min(values) -sum(values) sum(values) sum values min(values) min values heapq.heapify(values) heapq.heapify heapq heapify values next_nodes = deque() next_nodes deque() deque next_nodes.append(0) next_nodes.append next_nodes append 0 while next_nodes:
    node = next_nodes.popleft()
    nodes[node] = -heapq.heappop(values)
    for g in graph[node]:
        if not (nodes[g]):
            next_nodes.append(g) next_nodes node = next_nodes.popleft() node next_nodes.popleft() next_nodes.popleft next_nodes popleft nodes[node] = -heapq.heappop(values) nodes[node] nodes node -heapq.heappop(values) heapq.heappop(values) heapq.heappop heapq heappop values for g in graph[node]:
        if not (nodes[g]):
            next_nodes.append(g) g graph[node] graph node if not (nodes[g]):
            next_nodes.append(g) not (nodes[g]) nodes[g] nodes g next_nodes.append(g) next_nodes.append next_nodes append g print(*nodes) print *nodes nodes next_nodes = deque() deque() next_nodes node = next_nodes.popleft() next_nodes.popleft() node b = map(lambda x: int(x) - 1, input().split()) map(lambda x: int(x) - 1, input().split()) b nodes = [False for _ in range(n)] [False for _ in range(n)] nodes values = list(map(lambda x: -int(x), input().split())) list(map(lambda x: -int(x), input().split())) values n = int(input()) int(input()) n a, b = map(lambda x: int(x) - 1, input().split()) map(lambda x: int(x) - 1, input().split()) a graph = [set() for _ in range(n)] [set() for _ in range(n)] graph
import heapq
from collections import deque
n = int(input())
graph = [set() for _ in range(n)]

for _ in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    graph[a].add(b)
    graph[b].add(a)

nodes = [False for _ in range(n)]
values = list(map(lambda x: -int(x), input().split()))
print(-sum(values) + min(values))

heapq.heapify(values)
next_nodes = deque()
next_nodes.append(0)
while next_nodes:
    node = next_nodes.popleft()
    nodes[node] = -heapq.heappop(values)
    for g in graph[node]:
        if not (nodes[g]):
            next_nodes.append(g)

print(*nodes)