import sys
from collections import defaultdict as dd
import heapq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
e = dd(list)
inc = [0] * (N + 1)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
  inc[u] += 1
  inc[v] += 1
x = 0
for i in range(1, N + 1):
  if inc[x] < inc[i]: x = i

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

c = list(map(int, input().split()))
c.sort()
ressum = sum(c[: -1])
vis = set()
res = [0] * (N + 1)
res[x] = c[-1]
def dfs(y):
  global vis
  global res
  global c
  res[y] = c.pop()
  for z in e[y]:
    if z in vis: continue
    vis.add(z)
    dfs(z)
vis.add(x)
dfs(x)
print(ressum)
print(*res[1: ])