import sys
from collections import defaultdict as dd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
c = list(map(int, input().split()))
c.sort()
sm = sum(c) - c[-1]
res = [0] * (N + 1)
def dfs(x):
  global res
  res[x] = c.pop()
  for y in e[x]:
    if res[y]: continue
    dfs(y)
dfs(1)
print(sm)
print(*res[1: ]) import sys sys from collections import defaultdict as dd input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 N = int(input()) N int(input()) int input() input e = dd(list) e dd(list) dd list for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u) _ range(N - 1) range N - 1 N 1 u, v = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split v e[u].append(v) [u].append [u] e u append v e[v].append(u) [v].append [v] e v append u 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() c.sort c sort sm = sum(c) - c[-1] sm sum(c) - c[-1] sum(c) sum c c[-1] c -1 res = [0] * (N + 1) res [0] * (N + 1) [0] 0 N + 1 N 1 def dfs(x):
  global res
  res[x] = c.pop()
  for y in e[x]:
    if res[y]: continue
    dfs(y) dfs global res res[x] = c.pop() res[x] res x c.pop() c.pop c pop for y in e[x]:
    if res[y]: continue
    dfs(y) y e[x] e x if res[y]: continue
     res[y] res y dfs(y) dfs y x x dfs(1) dfs 1 print(sm) print sm print(*res[1: ]) print *res[1: ] res[1: ] res 1: 1 input = sys.stdin.readline sys.stdin.readline input u, v = map(int, input().split()) map(int, input().split()) u N = int(input()) int(input()) N c = list(map(int, input().split())) list(map(int, input().split())) c e = dd(list) dd(list) e def dfs(x):
  global res
  res[x] = c.pop()
  for y in e[x]:
    if res[y]: continue
    dfs(y) def dfs(x):
  global res
  res[x] = c.pop()
  for y in e[x]:
    if res[y]: continue
    dfs(y) dfs sm = sum(c) - c[-1] sum(c) - c[-1] sm v = map(int, input().split()) map(int, input().split()) v res = [0] * (N + 1) [0] * (N + 1) res
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
c = list(map(int, input().split()))
c.sort()
sm = sum(c) - c[-1]
res = [0] * (N + 1)
def dfs(x):
  global res
  res[x] = c.pop()
  for y in e[x]:
    if res[y]: continue
    dfs(y)
dfs(1)
print(sm)
print(*res[1: ])