import collections
import sys
input = sys.stdin.readline
import heapq
def solve():
  n = int(input())

  query2 = []
  edge = [[] for _ in range(n)]
  ans = [ 0 for i in range(n)]
  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    query2.append(a)
    query2.append(b)
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
  c = list(int(i) for i in input().split())
  if n == 1:
    print(0)
    print(c[0])
    exit()
  c = collections.deque(sorted(c,reverse =True))
  d = collections.Counter(query2)
  d2 = d.most_common()
  bfs = []
  heapq.heappush(bfs,(-1*d2[0][1],d2[0][0]-1))#回数,場所、親
  ct = 0
  visit = [False]*n
  
  while bfs:
    times,place = heapq.heappop(bfs)
    if visit[place]:
      continue
    else:
      visit[place] = True

      for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp))
      #print(place,parent,times)
      ans[place] = c.popleft()

      #print(c,place)

  print(sum(ans)-max(ans))
  print(*ans)
  
solve() import collections collections import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline import heapq heapq def solve():
  n = int(input())

  query2 = []
  edge = [[] for _ in range(n)]
  ans = [ 0 for i in range(n)]
  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    query2.append(a)
    query2.append(b)
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
  c = list(int(i) for i in input().split())
  if n == 1:
    print(0)
    print(c[0])
    exit()
  c = collections.deque(sorted(c,reverse =True))
  d = collections.Counter(query2)
  d2 = d.most_common()
  bfs = []
  heapq.heappush(bfs,(-1*d2[0][1],d2[0][0]-1))#回数,場所、親
  ct = 0
  visit = [False]*n
  
  while bfs:
    times,place = heapq.heappop(bfs)
    if visit[place]:
      continue
    else:
      visit[place] = True

      for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp))
      #print(place,parent,times)
      ans[place] = c.popleft()

      #print(c,place)

  print(sum(ans)-max(ans))
  print(*ans)
   solve n = int(input()) n int(input()) int input() input query2 = [] query2 [] [] 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)] 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)] for i in range(n-1):
    a,b = (int(i) for i in input().split())
    query2.append(a)
    query2.append(b)
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
   i range(n-1) range n-1 n 1 int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a,b = (int(i) for i in input().split()) a (int(i) for i in input().split()) b query2.append(a) query2.append query2 append a query2.append(b) query2.append query2 append b edge[a-1].append(b-1) [a-1].append [a-1] edge a-1 a 1 append b-1 b 1 edge[b-1].append(a-1) [b-1].append [b-1] edge b-1 b 1 append a-1 a 1 c = list(int(i) for i in input().split()) c list(int(i) for i in input().split()) list int(i) int i if n == 1:
    print(0)
    print(c[0])
    exit()
   n == 1 n 1 print(0) print 0 print(c[0]) print c[0] c 0 exit() exit c = collections.deque(sorted(c,reverse =True)) c collections.deque(sorted(c,reverse =True)) collections.deque collections deque sorted(c,reverse =True) sorted c reverse =True reverse True d = collections.Counter(query2) d collections.Counter(query2) collections.Counter collections Counter query2 d2 = d.most_common() d2 d.most_common() d.most_common d most_common bfs = [] bfs [] heapq.heappush(bfs,(-1*d2[0][1],d2[0][0]-1)) heapq.heappush heapq heappush bfs (-1*d2[0][1],d2[0][0]-1) -1*d2[0][1] -1 d2[0][1] [0] d2 0 1 d2[0][0]-1 d2[0][0] [0] d2 0 0 1 ct = 0 ct 0 visit = [False]*n visit [False]*n [False] False n while bfs:
    times,place = heapq.heappop(bfs)
    if visit[place]:
      continue
    else:
      visit[place] = True

      for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp))
      #print(place,parent,times)
      ans[place] = c.popleft()

      #print(c,place)

   bfs times,place = heapq.heappop(bfs) times heapq.heappop(bfs) heapq.heappop heapq heappop bfs place if visit[place]:
      continue
    else:
      visit[place] = True

      for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp))
      #print(place,parent,times)
      ans[place] = c.popleft()

      #print(c,place)

   visit[place] visit place continue visit[place] = True visit[place] visit place True for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp))
      #print(place,parent,times)
       i range(len(edge[place])) range len(edge[place]) len edge[place] edge place newp = edge[place][i] newp edge[place][i] [place] edge place i newtimes = len(edge[newp]) newtimes len(edge[newp]) len edge[newp] edge newp if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp))
      #print(place,parent,times)
       not visit[newp] visit[newp] visit newp heapq.heappush(bfs,(-1*newtimes,newp)) heapq.heappush heapq heappush bfs (-1*newtimes,newp) -1*newtimes -1 newtimes newp ans[place] = c.popleft() ans[place] ans place c.popleft() c.popleft c popleft print(sum(ans)-max(ans)) print sum(ans)-max(ans) sum(ans) sum ans max(ans) max ans print(*ans) print *ans ans solve() solve input = sys.stdin.readline sys.stdin.readline input def solve():
  n = int(input())

  query2 = []
  edge = [[] for _ in range(n)]
  ans = [ 0 for i in range(n)]
  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    query2.append(a)
    query2.append(b)
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
  c = list(int(i) for i in input().split())
  if n == 1:
    print(0)
    print(c[0])
    exit()
  c = collections.deque(sorted(c,reverse =True))
  d = collections.Counter(query2)
  d2 = d.most_common()
  bfs = []
  heapq.heappush(bfs,(-1*d2[0][1],d2[0][0]-1))#回数,場所、親
  ct = 0
  visit = [False]*n
  
  while bfs:
    times,place = heapq.heappop(bfs)
    if visit[place]:
      continue
    else:
      visit[place] = True

      for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp))
      #print(place,parent,times)
      ans[place] = c.popleft()

      #print(c,place)

  print(sum(ans)-max(ans))
  print(*ans)
   def solve():
  n = int(input())

  query2 = []
  edge = [[] for _ in range(n)]
  ans = [ 0 for i in range(n)]
  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    query2.append(a)
    query2.append(b)
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
  c = list(int(i) for i in input().split())
  if n == 1:
    print(0)
    print(c[0])
    exit()
  c = collections.deque(sorted(c,reverse =True))
  d = collections.Counter(query2)
  d2 = d.most_common()
  bfs = []
  heapq.heappush(bfs,(-1*d2[0][1],d2[0][0]-1))#回数,場所、親
  ct = 0
  visit = [False]*n
  
  while bfs:
    times,place = heapq.heappop(bfs)
    if visit[place]:
      continue
    else:
      visit[place] = True

      for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp))
      #print(place,parent,times)
      ans[place] = c.popleft()

      #print(c,place)

  print(sum(ans)-max(ans))
  print(*ans)
   solve
import collections
import sys
input = sys.stdin.readline
import heapq
def solve():
  n = int(input())

  query2 = []
  edge = [[] for _ in range(n)]
  ans = [ 0 for i in range(n)]
  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    query2.append(a)
    query2.append(b)
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
  c = list(int(i) for i in input().split())
  if n == 1:
    print(0)
    print(c[0])
    exit()
  c = collections.deque(sorted(c,reverse =True))
  d = collections.Counter(query2)
  d2 = d.most_common()
  bfs = []
  heapq.heappush(bfs,(-1*d2[0][1],d2[0][0]-1))#回数,場所、親
  ct = 0
  visit = [False]*n
  
  while bfs:
    times,place = heapq.heappop(bfs)
    if visit[place]:
      continue
    else:
      visit[place] = True

      for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp))
      #print(place,parent,times)
      ans[place] = c.popleft()

      #print(c,place)

  print(sum(ans)-max(ans))
  print(*ans)
  
solve()
