N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
C = sorted(list(map(int, input().split())))
M = sum(C[:-1])
import sys
sys.setrecursionlimit(10**8)

def dfs(v):
  for u in edge[v]:
    if nums[u]==-1:
      nums[u]=C.pop(-1)
      dfs(u)
  return 0

nums = [-1]*N
nums[0] = C.pop(-1)
dfs(0)

print(M)
print(*nums) 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) [] edge = [[] for _ in range(N)] edge [[] for _ in range(N)] for i in range(N-1):
  a,b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1) 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 edge[a-1].append(b-1) [a-1].append [a-1] edge a-1 a 1 append b-1 b 1 edge[b-1].append(a-1) [b-1].append [b-1] edge b-1 b 1 append a-1 a 1 C = sorted(list(map(int, input().split()))) C sorted(list(map(int, input().split()))) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M = sum(C[:-1]) M sum(C[:-1]) sum C[:-1] C :-1 -1 import sys sys sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 def dfs(v):
  for u in edge[v]:
    if nums[u]==-1:
      nums[u]=C.pop(-1)
      dfs(u)
  return 0 dfs for u in edge[v]:
    if nums[u]==-1:
      nums[u]=C.pop(-1)
      dfs(u)
   u edge[v] edge v if nums[u]==-1:
      nums[u]=C.pop(-1)
      dfs(u)
   nums[u]==-1 nums[u] nums u -1 nums[u]=C.pop(-1) nums[u] nums u C.pop(-1) C.pop C pop -1 dfs(u) dfs u return 0 0 v v nums = [-1]*N nums [-1]*N [-1] -1 N nums[0] = C.pop(-1) nums[0] nums 0 C.pop(-1) C.pop C pop -1 dfs(0) dfs 0 print(M) print M print(*nums) print *nums nums N = int(input()) int(input()) N C = sorted(list(map(int, input().split()))) sorted(list(map(int, input().split()))) C b = map(int, input().split()) map(int, input().split()) b def dfs(v):
  for u in edge[v]:
    if nums[u]==-1:
      nums[u]=C.pop(-1)
      dfs(u)
  return 0 def dfs(v):
  for u in edge[v]:
    if nums[u]==-1:
      nums[u]=C.pop(-1)
      dfs(u)
  return 0 dfs a,b = map(int, input().split()) map(int, input().split()) a M = sum(C[:-1]) sum(C[:-1]) M nums = [-1]*N [-1]*N nums edge = [[] for _ in range(N)] [[] for _ in range(N)] edge
N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
C = sorted(list(map(int, input().split())))
M = sum(C[:-1])
import sys
sys.setrecursionlimit(10**8)

def dfs(v):
  for u in edge[v]:
    if nums[u]==-1:
      nums[u]=C.pop(-1)
      dfs(u)
  return 0

nums = [-1]*N
nums[0] = C.pop(-1)
dfs(0)

print(M)
print(*nums)