n = int(input())
nodes = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    nodes[a].append(b)
    nodes[b].append(a)
# print(nodes)

c = list(map(int, input().split()))
c.sort(reverse=True)
# print(c)

count = 0
answer = [0 for _ in range(n)]
for i in range(n):
  end = True
  for j in range(n):
    if len(nodes[j]) == 1:
      end = False
      nodes[nodes[j][0]].remove(j)
      nodes[j].pop()
      answer[j] = c.pop()
      count += answer[j]
  if end:
    break
print(sum(answer))

answer[answer.index(0)] = c.pop()
print(' '.join(map(str, answer))) 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) [] nodes = [[] for _ in range(n)] nodes [[] for _ in range(n)] for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    nodes[a].append(b)
    nodes[b].append(a)
# print(nodes) i 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 nodes[a].append(b) [a].append [a] nodes a append b nodes[b].append(a) [b].append [b] nodes b append a c = list(map(int, input().split())) c list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c.sort(reverse=True) c.sort c sort reverse=True reverse True count = 0 count 0 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 answer = [0 for _ in range(n)] answer [0 for _ in range(n)] for i in range(n):
  end = True
  for j in range(n):
    if len(nodes[j]) == 1:
      end = False
      nodes[nodes[j][0]].remove(j)
      nodes[j].pop()
      answer[j] = c.pop()
      count += answer[j]
  if end:
    break i range(n) range n end = True end True for j in range(n):
    if len(nodes[j]) == 1:
      end = False
      nodes[nodes[j][0]].remove(j)
      nodes[j].pop()
      answer[j] = c.pop()
      count += answer[j]
   j range(n) range n if len(nodes[j]) == 1:
      end = False
      nodes[nodes[j][0]].remove(j)
      nodes[j].pop()
      answer[j] = c.pop()
      count += answer[j]
   len(nodes[j]) == 1 len(nodes[j]) len nodes[j] nodes j 1 end = False end False nodes[nodes[j][0]].remove(j) [nodes[j][0]].remove [nodes[j][0]] nodes nodes[j][0] [j] nodes j 0 remove j nodes[j].pop() [j].pop [j] nodes j pop answer[j] = c.pop() answer[j] answer j c.pop() c.pop c pop count += answer[j] count answer[j] answer j if end:
    break end break print(sum(answer)) print sum(answer) sum answer answer[answer.index(0)] = c.pop() answer[answer.index(0)] answer answer.index(0) answer.index answer index 0 c.pop() c.pop c pop print(' '.join(map(str, answer))) print ' '.join(map(str, answer)) ' '.join ' ' join map(str, answer) map str answer end = False False end b = map(int, input().split()) map(int, input().split()) b nodes = [[] for _ in range(n)] [[] for _ in range(n)] nodes c = list(map(int, input().split())) list(map(int, input().split())) c count = 0 0 count b -= 1 1 b end = True True end count += answer[j] answer[j] count a -= 1 1 a n = int(input()) int(input()) n answer = [0 for _ in range(n)] [0 for _ in range(n)] answer a, b = map(int, input().split()) map(int, input().split()) a
n = int(input())
nodes = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    nodes[a].append(b)
    nodes[b].append(a)
# print(nodes)

c = list(map(int, input().split()))
c.sort(reverse=True)
# print(c)

count = 0
answer = [0 for _ in range(n)]
for i in range(n):
  end = True
  for j in range(n):
    if len(nodes[j]) == 1:
      end = False
      nodes[nodes[j][0]].remove(j)
      nodes[j].pop()
      answer[j] = c.pop()
      count += answer[j]
  if end:
    break
print(sum(answer))

answer[answer.index(0)] = c.pop()
print(' '.join(map(str, answer)))
