N = int(input())
E=[list(map(int,input().split())) for i in range(N-1)]
C=list(map(int,input().split()))
C.sort(reverse=True)

print(sum(C[1:]))

ELIST = [[] for i in range(N+1)]
for a,b in E:
  ELIST[a].append(b)
  ELIST[b].append(a)


from collections import deque
QUE =deque([1])

i=0
ANS=[-1]*(N+1)
while QUE:
  x=QUE.pop()
  ANS[x]=C[i]
  i+=1
  for to in ELIST[x]:
    if ANS[to]==-1: 
      QUE.append(to)
      ANS[to]=0
      
print(*ANS[1:]) 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 E=[list(map(int,input().split())) for i in range(N-1)] E [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(reverse=True) C.sort C sort reverse=True reverse True print(sum(C[1:])) print sum(C[1:]) sum C[1:] C 1: 1 [] 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) [] ELIST = [[] for i in range(N+1)] ELIST [[] for i in range(N+1)] for a,b in E:
  ELIST[a].append(b)
  ELIST[b].append(a) a b E ELIST[a].append(b) [a].append [a] ELIST a append b ELIST[b].append(a) [b].append [b] ELIST b append a from collections import deque QUE =deque([1]) QUE deque([1]) deque [1] 1 i=0 i 0 ANS=[-1]*(N+1) ANS [-1]*(N+1) [-1] -1 N+1 N 1 while QUE:
  x=QUE.pop()
  ANS[x]=C[i]
  i+=1
  for to in ELIST[x]:
    if ANS[to]==-1: 
      QUE.append(to)
      ANS[to]=0
       QUE x=QUE.pop() x QUE.pop() QUE.pop QUE pop ANS[x]=C[i] ANS[x] ANS x C[i] C i i+=1 i 1 for to in ELIST[x]:
    if ANS[to]==-1: 
      QUE.append(to)
      ANS[to]=0
       to ELIST[x] ELIST x if ANS[to]==-1: 
      QUE.append(to)
      ANS[to]=0
       ANS[to]==-1 ANS[to] ANS to -1 QUE.append(to) QUE.append QUE append to ANS[to]=0 ANS[to] ANS to 0 print(*ANS[1:]) print *ANS[1:] ANS[1:] ANS 1: 1 E=[list(map(int,input().split())) for i in range(N-1)] [list(map(int,input().split())) for i in range(N-1)] E C=list(map(int,input().split())) list(map(int,input().split())) C x=QUE.pop() QUE.pop() x N = int(input()) int(input()) N QUE =deque([1]) deque([1]) QUE i=0 0 i ANS=[-1]*(N+1) [-1]*(N+1) ANS ELIST = [[] for i in range(N+1)] [[] for i in range(N+1)] ELIST i+=1 1 i
N = int(input())
E=[list(map(int,input().split())) for i in range(N-1)]
C=list(map(int,input().split()))
C.sort(reverse=True)

print(sum(C[1:]))

ELIST = [[] for i in range(N+1)]
for a,b in E:
  ELIST[a].append(b)
  ELIST[b].append(a)


from collections import deque
QUE =deque([1])

i=0
ANS=[-1]*(N+1)
while QUE:
  x=QUE.pop()
  ANS[x]=C[i]
  i+=1
  for to in ELIST[x]:
    if ANS[to]==-1: 
      QUE.append(to)
      ANS[to]=0
      
print(*ANS[1:])