#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

n=int(input())
v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1))
c=list(map(int,input().split()))
c.sort(reverse=True)
node=[[] for _ in range(n)]
d=deque()
d.append(0)
seen=[0]*n
seen[0]=1
ans=[0]*n
for pair in v:
    node[pair[0]].append(pair[1])
    node[pair[1]].append(pair[0])

s=0
while d:
    i=d.pop()
    ans[i]=c[s]
    s+=1
    for j in node[i]:
        if seen[j]==0:
            d.appendleft(j)
            seen[j]=1
print(sum(ans)-c[0])
print(*ans) import math math import itertools itertools from collections import deque from collections import Counter import heapq heapq from fractions  import gcd n=int(input()) n int(input()) int input() input v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1)) v tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1)) tuple tuple(map(lambda x: int(x)-1,input().split())) tuple map(lambda x: int(x)-1,input().split()) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split 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(reverse=True) c.sort c sort reverse=True reverse True [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] node=[[] for _ in range(n)] node [[] for _ in range(n)] d=deque() d deque() deque d.append(0) d.append d append 0 seen=[0]*n seen [0]*n [0] 0 n seen[0]=1 seen[0] seen 0 1 ans=[0]*n ans [0]*n [0] 0 n for pair in v:
    node[pair[0]].append(pair[1])
    node[pair[1]].append(pair[0]) pair v node[pair[0]].append(pair[1]) [pair[0]].append [pair[0]] node pair[0] pair 0 append pair[1] pair 1 node[pair[1]].append(pair[0]) [pair[1]].append [pair[1]] node pair[1] pair 1 append pair[0] pair 0 s=0 s 0 while d:
    i=d.pop()
    ans[i]=c[s]
    s+=1
    for j in node[i]:
        if seen[j]==0:
            d.appendleft(j)
            seen[j]=1 d i=d.pop() i d.pop() d.pop d pop ans[i]=c[s] ans[i] ans i c[s] c s s+=1 s 1 for j in node[i]:
        if seen[j]==0:
            d.appendleft(j)
            seen[j]=1 j node[i] node i if seen[j]==0:
            d.appendleft(j)
            seen[j]=1 seen[j]==0 seen[j] seen j 0 d.appendleft(j) d.appendleft d appendleft j seen[j]=1 seen[j] seen j 1 print(sum(ans)-c[0]) print sum(ans)-c[0] sum(ans) sum ans c[0] c 0 print(*ans) print *ans ans v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1)) tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1)) v d=deque() deque() d node=[[] for _ in range(n)] [[] for _ in range(n)] node ans=[0]*n [0]*n ans c=list(map(int,input().split())) list(map(int,input().split())) c s=0 0 s i=d.pop() d.pop() i s+=1 1 s seen=[0]*n [0]*n seen n=int(input()) int(input()) n
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

n=int(input())
v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1))
c=list(map(int,input().split()))
c.sort(reverse=True)
node=[[] for _ in range(n)]
d=deque()
d.append(0)
seen=[0]*n
seen[0]=1
ans=[0]*n
for pair in v:
    node[pair[0]].append(pair[1])
    node[pair[1]].append(pair[0])

s=0
while d:
    i=d.pop()
    ans[i]=c[s]
    s+=1
    for j in node[i]:
        if seen[j]==0:
            d.appendleft(j)
            seen[j]=1
print(sum(ans)-c[0])
print(*ans)