n=int(input())
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
c=list(map(int,input().split()))
c.sort(reverse=1)
print(sum(c)-c[0])
d=[-1]*n
d[0]=c[0]
Q=[0]
visited={0}
ind=1
while Q:
  P=[]
  for i in Q:
    for j in edge[i]:
      if j in visited:continue
      visited.add(j)
      d[j]=c[ind]
      ind+=1
      P.append(j)
  Q=P
print(*d) 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) [] edge=[[]for _ in range(n)] edge [[]for _ in range(n)] for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(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 a-=1 a 1 b-=1 b 1 edge[a].append(b) [a].append [a] edge a append b edge[b].append(a) [b].append [b] edge 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=1) c.sort c sort reverse=1 reverse 1 print(sum(c)-c[0]) print sum(c)-c[0] sum(c) sum c c[0] c 0 d=[-1]*n d [-1]*n [-1] -1 n d[0]=c[0] d[0] d 0 c[0] c 0 Q=[0] Q [0] 0 visited={0} visited {0} ind=1 ind 1 while Q:
  P=[]
  for i in Q:
    for j in edge[i]:
      if j in visited:continue
      visited.add(j)
      d[j]=c[ind]
      ind+=1
      P.append(j)
  Q=P Q P=[] P [] for i in Q:
    for j in edge[i]:
      if j in visited:continue
      visited.add(j)
      d[j]=c[ind]
      ind+=1
      P.append(j)
   i Q for j in edge[i]:
      if j in visited:continue
      visited.add(j)
      d[j]=c[ind]
      ind+=1
      P.append(j)
   j edge[i] edge i if j in visited:continue
       j in visited j visited visited.add(j) visited.add visited add j d[j]=c[ind] d[j] d j c[ind] c ind ind+=1 ind 1 P.append(j) P.append P append j Q=P Q P print(*d) print *d d visited={0} {0} visited ind=1 1 ind edge=[[]for _ in range(n)] [[]for _ in range(n)] edge a-=1 1 a b=map(int,input().split()) map(int,input().split()) b a,b=map(int,input().split()) map(int,input().split()) a ind+=1 1 ind Q=[0] [0] Q d=[-1]*n [-1]*n d c=list(map(int,input().split())) list(map(int,input().split())) c n=int(input()) int(input()) n b-=1 1 b Q=P P Q P=[] [] P
n=int(input())
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
c=list(map(int,input().split()))
c.sort(reverse=1)
print(sum(c)-c[0])
d=[-1]*n
d[0]=c[0]
Q=[0]
visited={0}
ind=1
while Q:
  P=[]
  for i in Q:
    for j in edge[i]:
      if j in visited:continue
      visited.add(j)
      d[j]=c[ind]
      ind+=1
      P.append(j)
  Q=P
print(*d)