# maximum sum of minimum
n=int(input())
node={i:[]for i in range(n+1)}
visited=[False for i in range(n+1)]

#尋ねたことがあるかどうか確認するためのリスト
first=0

for _ in range(n-1):
    a,b=map(int,input().split())
    node[a].append(b)
    node[b].append(a)
    if _==0:
        first+=a
        

dictionary=[0 for i in range(n+1)]
#答を格納するためのリスト
clist=list(map(int,input().split()))
clist=sorted(clist,reverse=True)
counter=0
dictionary[first]=clist[0]
K=sum(clist[1:])
from collections import deque
d=deque()
e=deque()
d.append(first)
visited[first]=True
while d:
    for some in d:
        for point in node[some]:
            if visited[point]==False:
                #まだ訪れたことのない頂点にあった場合
                counter+=1
                visited[point]=True
                dictionary[point]=clist[counter]
                e.append(point)
            else:
                pass
    d=e
    e=deque()
print(K)
print(*dictionary[1:]) n=int(input()) n int(input()) int input() input i:[]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) i [] node={i:[]for i in range(n+1)} node {i:[]for i in range(n+1)} False 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) False visited=[False for i in range(n+1)] visited [False for i in range(n+1)] first=0 first 0 for _ in range(n-1):
    a,b=map(int,input().split())
    node[a].append(b)
    node[b].append(a)
    if _==0:
        first+=a
         _ 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 node[a].append(b) [a].append [a] node a append b node[b].append(a) [b].append [b] node b append a if _==0:
        first+=a
         _==0 _ 0 first+=a first a 0 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) 0 dictionary=[0 for i in range(n+1)] dictionary [0 for i in range(n+1)] clist=list(map(int,input().split())) clist list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split clist=sorted(clist,reverse=True) clist sorted(clist,reverse=True) sorted clist reverse=True reverse True counter=0 counter 0 dictionary[first]=clist[0] dictionary[first] dictionary first clist[0] clist 0 K=sum(clist[1:]) K sum(clist[1:]) sum clist[1:] clist 1: 1 from collections import deque d=deque() d deque() deque e=deque() e deque() deque d.append(first) d.append d append first visited[first]=True visited[first] visited first True while d:
    for some in d:
        for point in node[some]:
            if visited[point]==False:
                #まだ訪れたことのない頂点にあった場合
                counter+=1
                visited[point]=True
                dictionary[point]=clist[counter]
                e.append(point)
            else:
                pass
    d=e
    e=deque() d for some in d:
        for point in node[some]:
            if visited[point]==False:
                #まだ訪れたことのない頂点にあった場合
                counter+=1
                visited[point]=True
                dictionary[point]=clist[counter]
                e.append(point)
            else:
                pass
     some d for point in node[some]:
            if visited[point]==False:
                #まだ訪れたことのない頂点にあった場合
                counter+=1
                visited[point]=True
                dictionary[point]=clist[counter]
                e.append(point)
            else:
                pass
     point node[some] node some if visited[point]==False:
                #まだ訪れたことのない頂点にあった場合
                counter+=1
                visited[point]=True
                dictionary[point]=clist[counter]
                e.append(point)
            else:
                pass
     visited[point]==False visited[point] visited point False counter+=1 counter 1 visited[point]=True visited[point] visited point True dictionary[point]=clist[counter] dictionary[point] dictionary point clist[counter] clist counter e.append(point) e.append e append point d=e d e e=deque() e deque() deque print(K) print K print(*dictionary[1:]) print *dictionary[1:] dictionary[1:] dictionary 1: 1 d=deque() deque() d dictionary=[0 for i in range(n+1)] [0 for i in range(n+1)] dictionary first=0 0 first n=int(input()) int(input()) n node={i:[]for i in range(n+1)} {i:[]for i in range(n+1)} node visited=[False for i in range(n+1)] [False for i in range(n+1)] visited first+=a a first e=deque() deque() e b=map(int,input().split()) map(int,input().split()) b a,b=map(int,input().split()) map(int,input().split()) a K=sum(clist[1:]) sum(clist[1:]) K counter=0 0 counter d=e e d counter+=1 1 counter clist=list(map(int,input().split())) list(map(int,input().split())) clist clist=sorted(clist,reverse=True) sorted(clist,reverse=True) clist e=deque() deque() e
# maximum sum of minimum
n=int(input())
node={i:[]for i in range(n+1)}
visited=[False for i in range(n+1)]

#尋ねたことがあるかどうか確認するためのリスト
first=0

for _ in range(n-1):
    a,b=map(int,input().split())
    node[a].append(b)
    node[b].append(a)
    if _==0:
        first+=a
        

dictionary=[0 for i in range(n+1)]
#答を格納するためのリスト
clist=list(map(int,input().split()))
clist=sorted(clist,reverse=True)
counter=0
dictionary[first]=clist[0]
K=sum(clist[1:])
from collections import deque
d=deque()
e=deque()
d.append(first)
visited[first]=True
while d:
    for some in d:
        for point in node[some]:
            if visited[point]==False:
                #まだ訪れたことのない頂点にあった場合
                counter+=1
                visited[point]=True
                dictionary[point]=clist[counter]
                e.append(point)
            else:
                pass
    d=e
    e=deque()
print(K)
print(*dictionary[1:])
