N=int(input())

G=[[] for i in range(N+1)]

for i in range(N-1):
    a,b=map(int,input().split())
    G[a].append(b)
    G[b].append(a)
C=list(map(int,input().split()))
C.sort(reverse=True)
S=sum(C[1:])

num=[0 for i in range(N+1)]
un_used=[True for i in range(N+1)]

q=[]
q.append(1)
un_used[1]=False

while q:
    node = q.pop(0)
    num[node] = C.pop(0)
    
    for i in range(len(G[node])):
        if un_used[G[node][i]]:
            un_used[G[node][i]]=False
            q.append(G[node][i])

print(S)
print(" ".join(map(str,num[1:]))) N=int(input()) N int(input()) int input() input [] 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) [] G=[[] for i in range(N+1)] G [[] for i in range(N+1)] for i in range(N-1):
    a,b=map(int,input().split())
    G[a].append(b)
    G[b].append(a) i 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 G[a].append(b) [a].append [a] G a append b G[b].append(a) [b].append [b] G b append a 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 S=sum(C[1:]) S sum(C[1:]) sum C[1:] C 1: 1 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 num=[0 for i in range(N+1)] num [0 for i in range(N+1)] True 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) True un_used=[True for i in range(N+1)] un_used [True for i in range(N+1)] q=[] q [] q.append(1) q.append q append 1 un_used[1]=False un_used[1] un_used 1 False while q:
    node = q.pop(0)
    num[node] = C.pop(0)
    
    for i in range(len(G[node])):
        if un_used[G[node][i]]:
            un_used[G[node][i]]=False
            q.append(G[node][i]) q node = q.pop(0) node q.pop(0) q.pop q pop 0 num[node] = C.pop(0) num[node] num node C.pop(0) C.pop C pop 0 for i in range(len(G[node])):
        if un_used[G[node][i]]:
            un_used[G[node][i]]=False
            q.append(G[node][i]) i range(len(G[node])) range len(G[node]) len G[node] G node if un_used[G[node][i]]:
            un_used[G[node][i]]=False
            q.append(G[node][i]) un_used[G[node][i]] un_used G[node][i] [node] G node i un_used[G[node][i]]=False un_used[G[node][i]] un_used G[node][i] [node] G node i False q.append(G[node][i]) q.append q append G[node][i] [node] G node i print(S) print S print(" ".join(map(str,num[1:]))) print " ".join(map(str,num[1:])) " ".join " " join map(str,num[1:]) map str num[1:] num 1: 1 b=map(int,input().split()) map(int,input().split()) b G=[[] for i in range(N+1)] [[] for i in range(N+1)] G num=[0 for i in range(N+1)] [0 for i in range(N+1)] num a,b=map(int,input().split()) map(int,input().split()) a un_used=[True for i in range(N+1)] [True for i in range(N+1)] un_used S=sum(C[1:]) sum(C[1:]) S node = q.pop(0) q.pop(0) node q=[] [] q N=int(input()) int(input()) N C=list(map(int,input().split())) list(map(int,input().split())) C
N=int(input())

G=[[] for i in range(N+1)]

for i in range(N-1):
    a,b=map(int,input().split())
    G[a].append(b)
    G[b].append(a)
C=list(map(int,input().split()))
C.sort(reverse=True)
S=sum(C[1:])

num=[0 for i in range(N+1)]
un_used=[True for i in range(N+1)]

q=[]
q.append(1)
un_used[1]=False

while q:
    node = q.pop(0)
    num[node] = C.pop(0)
    
    for i in range(len(G[node])):
        if un_used[G[node][i]]:
            un_used[G[node][i]]=False
            q.append(G[node][i])

print(S)
print(" ".join(map(str,num[1:])))