from collections import deque
import sys

sys.setrecursionlimit(10**7)

n=int(input())
to=[[] for _ in range(n)]
eda=[]
for _ in range(n-1):
  a,b=map(int,input().split())
  to[a-1].append(b-1)
  to[b-1].append(a-1)
  eda.append([a-1,b-1])
  
c=list(map(int,input().split()))

c.sort(reverse=True)

cd=deque(c)
poi=[0 for _ in range(n)] 
vi=[-1 for _ in range(n)]

vi[0]+=1
def dfs(now):
  vi[now]+=1
  v=cd.popleft()
  poi[now]+=v
  for i in to[now]:
    if vi[i]==-1:
      dfs(i)
  
dfs(0)

ans=0

for u in eda:
  x,y=u
  ans+=min(poi[x],poi[y])
  
print(ans)
for u in range(n):
  poi[u]=str(poi[u])
  
print(' '.join(poi))
      
 from collections import deque 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 _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] to=[[] for _ in range(n)] to [[] for _ in range(n)] eda=[] eda [] for _ in range(n-1):
  a,b=map(int,input().split())
  to[a-1].append(b-1)
  to[b-1].append(a-1)
  eda.append([a-1,b-1])
   _ 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 to[a-1].append(b-1) [a-1].append [a-1] to a-1 a 1 append b-1 b 1 to[b-1].append(a-1) [b-1].append [b-1] to b-1 b 1 append a-1 a 1 eda.append([a-1,b-1]) eda.append eda append [a-1,b-1] a-1 a 1 b-1 b 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(reverse=True) c.sort c sort reverse=True reverse True cd=deque(c) cd deque(c) deque c 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 poi=[0 for _ in range(n)] poi [0 for _ in range(n)] -1 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) -1 vi=[-1 for _ in range(n)] vi [-1 for _ in range(n)] vi[0]+=1 vi[0] vi 0 1 def dfs(now):
  vi[now]+=1
  v=cd.popleft()
  poi[now]+=v
  for i in to[now]:
    if vi[i]==-1:
      dfs(i)
   dfs vi[now]+=1 vi[now] vi now 1 v=cd.popleft() v cd.popleft() cd.popleft cd popleft poi[now]+=v poi[now] poi now v for i in to[now]:
    if vi[i]==-1:
      dfs(i)
   i to[now] to now if vi[i]==-1:
      dfs(i)
   vi[i]==-1 vi[i] vi i -1 dfs(i) dfs i now now dfs(0) dfs 0 ans=0 ans 0 for u in eda:
  x,y=u
  ans+=min(poi[x],poi[y])
   u eda x,y=u x u y ans+=min(poi[x],poi[y]) ans min(poi[x],poi[y]) min poi[x] poi x poi[y] poi y print(ans) print ans for u in range(n):
  poi[u]=str(poi[u])
   u range(n) range n poi[u]=str(poi[u]) poi[u] poi u str(poi[u]) str poi[u] poi u print(' '.join(poi)) print ' '.join(poi) ' '.join ' ' join poi c=list(map(int,input().split())) list(map(int,input().split())) c y=u u y a,b=map(int,input().split()) map(int,input().split()) a x,y=u u x eda=[] [] eda def dfs(now):
  vi[now]+=1
  v=cd.popleft()
  poi[now]+=v
  for i in to[now]:
    if vi[i]==-1:
      dfs(i)
   def dfs(now):
  vi[now]+=1
  v=cd.popleft()
  poi[now]+=v
  for i in to[now]:
    if vi[i]==-1:
      dfs(i)
   dfs cd=deque(c) deque(c) cd to=[[] for _ in range(n)] [[] for _ in range(n)] to poi=[0 for _ in range(n)] [0 for _ in range(n)] poi b=map(int,input().split()) map(int,input().split()) b ans=0 0 ans vi=[-1 for _ in range(n)] [-1 for _ in range(n)] vi ans+=min(poi[x],poi[y]) min(poi[x],poi[y]) ans n=int(input()) int(input()) n
from collections import deque
import sys

sys.setrecursionlimit(10**7)

n=int(input())
to=[[] for _ in range(n)]
eda=[]
for _ in range(n-1):
  a,b=map(int,input().split())
  to[a-1].append(b-1)
  to[b-1].append(a-1)
  eda.append([a-1,b-1])
  
c=list(map(int,input().split()))

c.sort(reverse=True)

cd=deque(c)
poi=[0 for _ in range(n)] 
vi=[-1 for _ in range(n)]

vi[0]+=1
def dfs(now):
  vi[now]+=1
  v=cd.popleft()
  poi[now]+=v
  for i in to[now]:
    if vi[i]==-1:
      dfs(i)
  
dfs(0)

ans=0

for u in eda:
  x,y=u
  ans+=min(poi[x],poi[y])
  
print(ans)
for u in range(n):
  poi[u]=str(poi[u])
  
print(' '.join(poi))
      

