import sys
sys.setrecursionlimit(10 ** 9)
import heapq

N = int(input())
E = [list(map(lambda x: int(x)-1,input().split())) for _ in range(N-1)]
C = sorted(list(map(lambda x: int(x)*(-1),input().split())))
m = -sum(C[1:])
heapq.heapify(C)

V = [set() for _ in range(N)]
for u,v in E:
  V[u].add(v)
  V[v].add(u)

A = [0 for _ in range(N)]
def dfs(v,s):
  A[v] = -heapq.heappop(C)
  for u in V[v]:
    if u != s:
      dfs(u,v)
dfs(0,-1)

print(m)
print(*A) import sys sys sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 import heapq heapq N = int(input()) N int(input()) int input() input list(map(lambda x: int(x)-1,input().split())) for _ in range(N-1) for _ in range(N-1) _ range(N-1) range N-1 N 1 for _ in range(N-1) list(map(lambda x: int(x)-1,input().split())) list 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 E = [list(map(lambda x: int(x)-1,input().split())) for _ in range(N-1)] E [list(map(lambda x: int(x)-1,input().split())) for _ in range(N-1)] C = sorted(list(map(lambda x: int(x)*(-1),input().split()))) C sorted(list(map(lambda x: int(x)*(-1),input().split()))) sorted list(map(lambda x: int(x)*(-1),input().split())) list 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 m = -sum(C[1:]) m -sum(C[1:]) sum(C[1:]) sum C[1:] C 1: 1 heapq.heapify(C) heapq.heapify heapq heapify C set() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) set() set V = [set() for _ in range(N)] V [set() for _ in range(N)] for u,v in E:
  V[u].add(v)
  V[v].add(u) u v E V[u].add(v) [u].add [u] V u add v V[v].add(u) [v].add [v] V v add u 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 A = [0 for _ in range(N)] A [0 for _ in range(N)] def dfs(v,s):
  A[v] = -heapq.heappop(C)
  for u in V[v]:
    if u != s:
      dfs(u,v) dfs A[v] = -heapq.heappop(C) A[v] A v -heapq.heappop(C) heapq.heappop(C) heapq.heappop heapq heappop C for u in V[v]:
    if u != s:
      dfs(u,v) u V[v] V v if u != s:
      dfs(u,v) u != s u s dfs(u,v) dfs u v v v s s dfs(0,-1) dfs 0 -1 print(m) print m print(*A) print *A A A = [0 for _ in range(N)] [0 for _ in range(N)] A E = [list(map(lambda x: int(x)-1,input().split())) for _ in range(N-1)] [list(map(lambda x: int(x)-1,input().split())) for _ in range(N-1)] E V = [set() for _ in range(N)] [set() for _ in range(N)] V C = sorted(list(map(lambda x: int(x)*(-1),input().split()))) sorted(list(map(lambda x: int(x)*(-1),input().split()))) C m = -sum(C[1:]) -sum(C[1:]) m N = int(input()) int(input()) N def dfs(v,s):
  A[v] = -heapq.heappop(C)
  for u in V[v]:
    if u != s:
      dfs(u,v) def dfs(v,s):
  A[v] = -heapq.heappop(C)
  for u in V[v]:
    if u != s:
      dfs(u,v) dfs
import sys
sys.setrecursionlimit(10 ** 9)
import heapq

N = int(input())
E = [list(map(lambda x: int(x)-1,input().split())) for _ in range(N-1)]
C = sorted(list(map(lambda x: int(x)*(-1),input().split())))
m = -sum(C[1:])
heapq.heapify(C)

V = [set() for _ in range(N)]
for u,v in E:
  V[u].add(v)
  V[v].add(u)

A = [0 for _ in range(N)]
def dfs(v,s):
  A[v] = -heapq.heappop(C)
  for u in V[v]:
    if u != s:
      dfs(u,v)
dfs(0,-1)

print(m)
print(*A)
