import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]
c=list(map(int,input().split()))
c.sort()
print(sum(c)-c[-1])
lst=[[] for i in range(n)]
nodelst=[0]*n
ans=0
for i in range(n-1):
    a,b=ab[i]
    lst[a-1].append(b)
    lst[b-1].append(a)

# print(lst)
nodelst[0]=c[-1]
d=deque(lst[0])
cnt=-2
while d:
    tmp=d.popleft()-1
    if nodelst[tmp]==0:
        nodelst[tmp]=c[cnt]
        cnt-=1
        d+=lst[tmp]
print(*nodelst) import sys sys from collections import * import heapq heapq import math math import bisect bisect from itertools import permutations,accumulate,combinations,product from fractions import gcd def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 mod=10**9+7 mod 10**9+7 10**9 10 9 7 n=int(input()) n int(input()) int input() input list(map(int,input().split())) 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) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ab=[list(map(int,input().split())) for i in range(n-1)] ab [list(map(int,input().split())) for i in range(n-1)] 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 print(sum(c)-c[-1]) print sum(c)-c[-1] sum(c) sum c c[-1] c -1 [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] lst=[[] for i in range(n)] lst [[] for i in range(n)] nodelst=[0]*n nodelst [0]*n [0] 0 n ans=0 ans 0 for i in range(n-1):
    a,b=ab[i]
    lst[a-1].append(b)
    lst[b-1].append(a)

# print(lst) i range(n-1) range n-1 n 1 a,b=ab[i] a ab[i] ab i b lst[a-1].append(b) [a-1].append [a-1] lst a-1 a 1 append b lst[b-1].append(a) [b-1].append [b-1] lst b-1 b 1 append a nodelst[0]=c[-1] nodelst[0] nodelst 0 c[-1] c -1 d=deque(lst[0]) d deque(lst[0]) deque lst[0] lst 0 cnt=-2 cnt -2 while d:
    tmp=d.popleft()-1
    if nodelst[tmp]==0:
        nodelst[tmp]=c[cnt]
        cnt-=1
        d+=lst[tmp] d tmp=d.popleft()-1 tmp d.popleft()-1 d.popleft() d.popleft d popleft 1 if nodelst[tmp]==0:
        nodelst[tmp]=c[cnt]
        cnt-=1
        d+=lst[tmp] nodelst[tmp]==0 nodelst[tmp] nodelst tmp 0 nodelst[tmp]=c[cnt] nodelst[tmp] nodelst tmp c[cnt] c cnt cnt-=1 cnt 1 d+=lst[tmp] d lst[tmp] lst tmp print(*nodelst) print *nodelst nodelst cnt-=1 1 cnt n=int(input()) int(input()) n nodelst=[0]*n [0]*n nodelst ans=0 0 ans cnt=-2 -2 cnt def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input b=ab[i] ab[i] b ab=[list(map(int,input().split())) for i in range(n-1)] [list(map(int,input().split())) for i in range(n-1)] ab mod=10**9+7 10**9+7 mod tmp=d.popleft()-1 d.popleft()-1 tmp c=list(map(int,input().split())) list(map(int,input().split())) c lst=[[] for i in range(n)] [[] for i in range(n)] lst a,b=ab[i] ab[i] a d+=lst[tmp] lst[tmp] d d=deque(lst[0]) deque(lst[0]) d
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]
c=list(map(int,input().split()))
c.sort()
print(sum(c)-c[-1])
lst=[[] for i in range(n)]
nodelst=[0]*n
ans=0
for i in range(n-1):
    a,b=ab[i]
    lst[a-1].append(b)
    lst[b-1].append(a)

# print(lst)
nodelst[0]=c[-1]
d=deque(lst[0])
cnt=-2
while d:
    tmp=d.popleft()-1
    if nodelst[tmp]==0:
        nodelst[tmp]=c[cnt]
        cnt-=1
        d+=lst[tmp]
print(*nodelst)