# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

prepare=[]
n=I()
tree=[[] for i in range(n)]
for i in range(n-1):
    a,b=MI()
    a-=1
    b-=1
    prepare.append([a,b])
    tree[a].append(b)
    tree[b].append(a)
lis=sorted(LI(),reverse=True)
answers=[0 for i in range(n)]
Q=deque([0])
answers[0]=lis[0]
count=1
while Q:
    q=Q.popleft()
    for x in tree[q]:
        if answers[x]==0:
            answers[x]=lis[count]
            Q.append(x)
            count+=1
#print(answers)
ans=0
for i in range(n-1):
    ans+=min(answers[prepare[i][0]],answers[prepare[i][1]])
print(ans)
print(*answers) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial from operator import itemgetter def I(): return int(input()) I def MI(): return map(int, input().split()) MI def LI(): return list(map(int, input().split())) LI int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input def LI2(): return [int(input()) for i in range(n)] LI2 [LI()]for i in range(n) for i in range(n) i range(n) range n for i in range(n) [LI()] LI() LI def MXI(): return [[LI()]for i in range(n)] MXI def SI(): return input().rstrip() SI def printns(x): print('\n'.join(x)) printns x x def printni(x): print('\n'.join(list(map(str,x)))) printni x x inf = 10**17 inf 10**17 10 17 mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 prepare=[] prepare [] n=I() n I() I [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] tree=[[] for i in range(n)] tree [[] for i in range(n)] for i in range(n-1):
    a,b=MI()
    a-=1
    b-=1
    prepare.append([a,b])
    tree[a].append(b)
    tree[b].append(a) i range(n-1) range n-1 n 1 a,b=MI() a MI() MI b a-=1 a 1 b-=1 b 1 prepare.append([a,b]) prepare.append prepare append [a,b] a b tree[a].append(b) [a].append [a] tree a append b tree[b].append(a) [b].append [b] tree b append a lis=sorted(LI(),reverse=True) lis sorted(LI(),reverse=True) sorted LI() LI reverse=True reverse True 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 answers=[0 for i in range(n)] answers [0 for i in range(n)] Q=deque([0]) Q deque([0]) deque [0] 0 answers[0]=lis[0] answers[0] answers 0 lis[0] lis 0 count=1 count 1 while Q:
    q=Q.popleft()
    for x in tree[q]:
        if answers[x]==0:
            answers[x]=lis[count]
            Q.append(x)
            count+=1
#print(answers) Q q=Q.popleft() q Q.popleft() Q.popleft Q popleft for x in tree[q]:
        if answers[x]==0:
            answers[x]=lis[count]
            Q.append(x)
            count+=1
#print(answers) x tree[q] tree q if answers[x]==0:
            answers[x]=lis[count]
            Q.append(x)
            count+=1
#print(answers) answers[x]==0 answers[x] answers x 0 answers[x]=lis[count] answers[x] answers x lis[count] lis count Q.append(x) Q.append Q append x count+=1 count 1 ans=0 ans 0 for i in range(n-1):
    ans+=min(answers[prepare[i][0]],answers[prepare[i][1]]) i range(n-1) range n-1 n 1 ans+=min(answers[prepare[i][0]],answers[prepare[i][1]]) ans min(answers[prepare[i][0]],answers[prepare[i][1]]) min answers[prepare[i][0]] answers prepare[i][0] [i] prepare i 0 answers[prepare[i][1]] answers prepare[i][1] [i] prepare i 1 print(ans) print ans print(*answers) print *answers answers b=MI() MI() b def MXI(): return [[LI()]for i in range(n)] def MXI(): return [[LI()]for i in range(n)] MXI def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI def printni(x): print('\n'.join(list(map(str,x)))) def printni(x): print('\n'.join(list(map(str,x)))) printni count=1 1 count inf = 10**17 10**17 inf b-=1 1 b prepare=[] [] prepare answers=[0 for i in range(n)] [0 for i in range(n)] answers ans+=min(answers[prepare[i][0]],answers[prepare[i][1]]) min(answers[prepare[i][0]],answers[prepare[i][1]]) ans def SI(): return input().rstrip() def SI(): return input().rstrip() SI count+=1 1 count lis=sorted(LI(),reverse=True) sorted(LI(),reverse=True) lis n=I() I() n input = sys.stdin.readline sys.stdin.readline input def I(): return int(input()) def I(): return int(input()) I mod = 10**9 + 7 10**9 + 7 mod tree=[[] for i in range(n)] [[] for i in range(n)] tree Q=deque([0]) deque([0]) Q ans=0 0 ans a-=1 1 a a,b=MI() MI() a def printns(x): print('\n'.join(x)) def printns(x): print('\n'.join(x)) printns q=Q.popleft() Q.popleft() q def MI(): return map(int, input().split()) def MI(): return map(int, input().split()) MI def LI2(): return [int(input()) for i in range(n)] def LI2(): return [int(input()) for i in range(n)] LI2
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

prepare=[]
n=I()
tree=[[] for i in range(n)]
for i in range(n-1):
    a,b=MI()
    a-=1
    b-=1
    prepare.append([a,b])
    tree[a].append(b)
    tree[b].append(a)
lis=sorted(LI(),reverse=True)
answers=[0 for i in range(n)]
Q=deque([0])
answers[0]=lis[0]
count=1
while Q:
    q=Q.popleft()
    for x in tree[q]:
        if answers[x]==0:
            answers[x]=lis[count]
            Q.append(x)
            count+=1
#print(answers)
ans=0
for i in range(n-1):
    ans+=min(answers[prepare[i][0]],answers[prepare[i][1]])
print(ans)
print(*answers)