from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())
D =[[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    D[a].append(b)
    D[b].append(a)

c = sorted(list(map(int,input().split())))
vcost = [-1]*(N+1)
vcost[1]=c.pop()
ans = 0
def dfs(i):
    global ans
    for j in D[i]:
        if vcost[j]==-1:
            vcost[j]=c.pop()
            ans += vcost[j]
            dfs(j)
dfs(1)
print(ans)
print(*vcost[1:]) from itertools import* import math math from collections import* from heapq import* from bisect import bisect_left,bisect_right from copy import deepcopy inf = float("inf") inf float("inf") float "inf" mod = 10**9+7 mod 10**9+7 10**9 10 9 7 from functools import reduce import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 N = int(input()) N int(input()) int input() input [] for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [] D =[[] for i in range(N+1)] D [[] for i in range(N+1)] for i in range(N-1):
    a,b = map(int,input().split())
    D[a].append(b)
    D[b].append(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 D[a].append(b) [a].append [a] D a append b D[b].append(a) [b].append [b] D b append a 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 vcost = [-1]*(N+1) vcost [-1]*(N+1) [-1] -1 N+1 N 1 vcost[1]=c.pop() vcost[1] vcost 1 c.pop() c.pop c pop ans = 0 ans 0 def dfs(i):
    global ans
    for j in D[i]:
        if vcost[j]==-1:
            vcost[j]=c.pop()
            ans += vcost[j]
            dfs(j) dfs global ans for j in D[i]:
        if vcost[j]==-1:
            vcost[j]=c.pop()
            ans += vcost[j]
            dfs(j) j D[i] D i if vcost[j]==-1:
            vcost[j]=c.pop()
            ans += vcost[j]
            dfs(j) vcost[j]==-1 vcost[j] vcost j -1 vcost[j]=c.pop() vcost[j] vcost j c.pop() c.pop c pop ans += vcost[j] ans vcost[j] vcost j dfs(j) dfs j i i dfs(1) dfs 1 print(ans) print ans print(*vcost[1:]) print *vcost[1:] vcost[1:] vcost 1: 1 mod = 10**9+7 10**9+7 mod N = int(input()) int(input()) N D =[[] for i in range(N+1)] [[] for i in range(N+1)] D ans = 0 0 ans def dfs(i):
    global ans
    for j in D[i]:
        if vcost[j]==-1:
            vcost[j]=c.pop()
            ans += vcost[j]
            dfs(j) def dfs(i):
    global ans
    for j in D[i]:
        if vcost[j]==-1:
            vcost[j]=c.pop()
            ans += vcost[j]
            dfs(j) dfs vcost = [-1]*(N+1) [-1]*(N+1) vcost b = map(int,input().split()) map(int,input().split()) b inf = float("inf") float("inf") inf a,b = map(int,input().split()) map(int,input().split()) a c = sorted(list(map(int,input().split()))) sorted(list(map(int,input().split()))) c
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())
D =[[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    D[a].append(b)
    D[b].append(a)

c = sorted(list(map(int,input().split())))
vcost = [-1]*(N+1)
vcost[1]=c.pop()
ans = 0
def dfs(i):
    global ans
    for j in D[i]:
        if vcost[j]==-1:
            vcost[j]=c.pop()
            ans += vcost[j]
            dfs(j)
dfs(1)
print(ans)
print(*vcost[1:])