n=int(input())
e=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(lambda x:int(x)-1,input().split())
  e[a].append(b)
  e[b].append(a)
c=list(map(int,input().split()))
c.sort()
print(sum(c[:-1]))

c.reverse()
ans=[0 for i in range(n)]
ans[0]=c[0]
k=1

s=[0]
while s:
  ns=[]
  for i in s:
    for j in e[i]:
      if ans[j]:
        continue
      ans[j]=c[k]
      k+=1
      ns.append(j)
  s=ns
print(" ".join(map(str,ans))) n=int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] e=[[] for i in range(n)] e [[] for i in range(n)] for i in range(n-1):
  a,b=map(lambda x:int(x)-1,input().split())
  e[a].append(b)
  e[b].append(a) i range(n-1) range n-1 n 1 a,b=map(lambda x:int(x)-1,input().split()) a map(lambda x:int(x)-1,input().split()) map lambda x:int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split b e[a].append(b) [a].append [a] e a append b e[b].append(a) [b].append [b] e 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() c.sort c sort print(sum(c[:-1])) print sum(c[:-1]) sum c[:-1] c :-1 -1 c.reverse() c.reverse c reverse 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 ans=[0 for i in range(n)] ans [0 for i in range(n)] ans[0]=c[0] ans[0] ans 0 c[0] c 0 k=1 k 1 s=[0] s [0] 0 while s:
  ns=[]
  for i in s:
    for j in e[i]:
      if ans[j]:
        continue
      ans[j]=c[k]
      k+=1
      ns.append(j)
  s=ns s ns=[] ns [] for i in s:
    for j in e[i]:
      if ans[j]:
        continue
      ans[j]=c[k]
      k+=1
      ns.append(j)
   i s for j in e[i]:
      if ans[j]:
        continue
      ans[j]=c[k]
      k+=1
      ns.append(j)
   j e[i] e i if ans[j]:
        continue
       ans[j] ans j continue ans[j]=c[k] ans[j] ans j c[k] c k k+=1 k 1 ns.append(j) ns.append ns append j s=ns s ns print(" ".join(map(str,ans))) print " ".join(map(str,ans)) " ".join " " join map(str,ans) map str ans b=map(lambda x:int(x)-1,input().split()) map(lambda x:int(x)-1,input().split()) b s=[0] [0] s k=1 1 k k+=1 1 k ns=[] [] ns a,b=map(lambda x:int(x)-1,input().split()) map(lambda x:int(x)-1,input().split()) a e=[[] for i in range(n)] [[] for i in range(n)] e n=int(input()) int(input()) n ans=[0 for i in range(n)] [0 for i in range(n)] ans s=ns ns s c=list(map(int,input().split())) list(map(int,input().split())) c
n=int(input())
e=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(lambda x:int(x)-1,input().split())
  e[a].append(b)
  e[b].append(a)
c=list(map(int,input().split()))
c.sort()
print(sum(c[:-1]))

c.reverse()
ans=[0 for i in range(n)]
ans[0]=c[0]
k=1

s=[0]
while s:
  ns=[]
  for i in s:
    for j in e[i]:
      if ans[j]:
        continue
      ans[j]=c[k]
      k+=1
      ns.append(j)
  s=ns
print(" ".join(map(str,ans)))
