N = int(input())
E = [set() for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  E[a].add(b)
  E[b].add(a)
cs = list(map(int, input().split()))
cs.sort()
M = sum(cs[:-1])
ds = [-1]*N
ds[0] = cs.pop()
q = [0]
while q:
  c = q.pop()
  ns = E[c]
  for n in ns:
    if ds[n] < 0:
      ds[n] = cs.pop()
      q.append(n)
print(M)
print(" ".join(map(str, ds))) N = int(input()) N int(input()) int input() input set() for i in range(N) for i in range(N) i range(N) range N for i in range(N) set() set E = [set() for i in range(N)] E [set() for i in range(N)] for i in range(N-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  E[a].add(b)
  E[b].add(a) 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, b = a-1, b-1 a a-1 a 1 b b-1 b 1 E[a].add(b) [a].add [a] E a add b E[b].add(a) [b].add [b] E b add a cs = list(map(int, input().split())) cs list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cs.sort() cs.sort cs sort M = sum(cs[:-1]) M sum(cs[:-1]) sum cs[:-1] cs :-1 -1 ds = [-1]*N ds [-1]*N [-1] -1 N ds[0] = cs.pop() ds[0] ds 0 cs.pop() cs.pop cs pop q = [0] q [0] 0 while q:
  c = q.pop()
  ns = E[c]
  for n in ns:
    if ds[n] < 0:
      ds[n] = cs.pop()
      q.append(n) q c = q.pop() c q.pop() q.pop q pop ns = E[c] ns E[c] E c for n in ns:
    if ds[n] < 0:
      ds[n] = cs.pop()
      q.append(n) n ns if ds[n] < 0:
      ds[n] = cs.pop()
      q.append(n) ds[n] < 0 ds[n] ds n 0 ds[n] = cs.pop() ds[n] ds n cs.pop() cs.pop cs pop q.append(n) q.append q append n print(M) print M print(" ".join(map(str, ds))) print " ".join(map(str, ds)) " ".join " " join map(str, ds) map str ds cs = list(map(int, input().split())) list(map(int, input().split())) cs M = sum(cs[:-1]) sum(cs[:-1]) M q = [0] [0] q b = map(int, input().split()) map(int, input().split()) b ns = E[c] E[c] ns b = a-1, b-1 b-1 b a, b = map(int, input().split()) map(int, input().split()) a c = q.pop() q.pop() c E = [set() for i in range(N)] [set() for i in range(N)] E ds = [-1]*N [-1]*N ds N = int(input()) int(input()) N a, b = a-1, b-1 a-1 a
N = int(input())
E = [set() for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  E[a].add(b)
  E[b].add(a)
cs = list(map(int, input().split()))
cs.sort()
M = sum(cs[:-1])
ds = [-1]*N
ds[0] = cs.pop()
q = [0]
while q:
  c = q.pop()
  ns = E[c]
  for n in ns:
    if ds[n] < 0:
      ds[n] = cs.pop()
      q.append(n)
print(M)
print(" ".join(map(str, ds)))
