n = int(input())
T = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  T[a].append(b)
  T[b].append(a)
C = sorted(map(int, input().split()))
print(sum(C[:-1]))
L = [-1]*n
stack = [0]
while stack:
  temp = stack.pop()
  L[temp] = C.pop()
  for v in T[temp]:
    if L[v] == -1:
      stack.append(v)
print(*L) n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] T = [[] for _ in range(n)] T [[] for _ in range(n)] for _ in range(n-1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  T[a].append(b)
  T[b].append(a) _ range(n-1) range n-1 n 1 a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b a -= 1 a 1 b -= 1 b 1 T[a].append(b) [a].append [a] T a append b T[b].append(a) [b].append [b] T b append a C = sorted(map(int, input().split())) C sorted(map(int, input().split())) sorted map(int, input().split()) map int input().split() ().split () input split print(sum(C[:-1])) print sum(C[:-1]) sum C[:-1] C :-1 -1 L = [-1]*n L [-1]*n [-1] -1 n stack = [0] stack [0] 0 while stack:
  temp = stack.pop()
  L[temp] = C.pop()
  for v in T[temp]:
    if L[v] == -1:
      stack.append(v) stack temp = stack.pop() temp stack.pop() stack.pop stack pop L[temp] = C.pop() L[temp] L temp C.pop() C.pop C pop for v in T[temp]:
    if L[v] == -1:
      stack.append(v) v T[temp] T temp if L[v] == -1:
      stack.append(v) L[v] == -1 L[v] L v -1 stack.append(v) stack.append stack append v print(*L) print *L L a, b = map(int, input().split()) map(int, input().split()) a a -= 1 1 a C = sorted(map(int, input().split())) sorted(map(int, input().split())) C L = [-1]*n [-1]*n L b = map(int, input().split()) map(int, input().split()) b temp = stack.pop() stack.pop() temp stack = [0] [0] stack n = int(input()) int(input()) n b -= 1 1 b T = [[] for _ in range(n)] [[] for _ in range(n)] T
n = int(input())
T = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  T[a].append(b)
  T[b].append(a)
C = sorted(map(int, input().split()))
print(sum(C[:-1]))
L = [-1]*n
stack = [0]
while stack:
  temp = stack.pop()
  L[temp] = C.pop()
  for v in T[temp]:
    if L[v] == -1:
      stack.append(v)
print(*L)