#解説チラ見
n = int(input())
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append(b)
  peer[b].append(a)
now = [0]
scr = list(map(int,input().split()))
scr.sort()
scr.reverse()
ans = [0 for _ in range(n)]
ans[0] = scr[0]
pin = 1
while now:
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if ans[y] == 0:
        ans[y] = scr[pin]
        pin += 1
        now.append(y)
print(sum(scr[1:]))
print(' '.join(list(map(str,ans)))) 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) [] peer = [[] for _ in range(n)] peer [[] for _ in range(n)] for _ in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append(b)
  peer[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 peer[a].append(b) [a].append [a] peer a append b peer[b].append(a) [b].append [b] peer b append a now = [0] now [0] 0 scr = list(map(int,input().split())) scr list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split scr.sort() scr.sort scr sort scr.reverse() scr.reverse scr reverse 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 ans = [0 for _ in range(n)] ans [0 for _ in range(n)] ans[0] = scr[0] ans[0] ans 0 scr[0] scr 0 pin = 1 pin 1 while now:
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if ans[y] == 0:
        ans[y] = scr[pin]
        pin += 1
        now.append(y) now last = now last now now = [] now [] for x in last:
    for y in peer[x]:
      if ans[y] == 0:
        ans[y] = scr[pin]
        pin += 1
        now.append(y) x last for y in peer[x]:
      if ans[y] == 0:
        ans[y] = scr[pin]
        pin += 1
        now.append(y) y peer[x] peer x if ans[y] == 0:
        ans[y] = scr[pin]
        pin += 1
        now.append(y) ans[y] == 0 ans[y] ans y 0 ans[y] = scr[pin] ans[y] ans y scr[pin] scr pin pin += 1 pin 1 now.append(y) now.append now append y print(sum(scr[1:])) print sum(scr[1:]) sum scr[1:] scr 1: 1 print(' '.join(list(map(str,ans)))) print ' '.join(list(map(str,ans))) ' '.join ' ' join list(map(str,ans)) list map(str,ans) map str ans a -= 1 1 a n = int(input()) int(input()) n scr = list(map(int,input().split())) list(map(int,input().split())) scr ans = [0 for _ in range(n)] [0 for _ in range(n)] ans b -= 1 1 b now = [] [] now peer = [[] for _ in range(n)] [[] for _ in range(n)] peer b = map(int,input().split()) map(int,input().split()) b a,b = map(int,input().split()) map(int,input().split()) a pin = 1 1 pin last = now now last pin += 1 1 pin now = [0] [0] now
#解説チラ見
n = int(input())
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append(b)
  peer[b].append(a)
now = [0]
scr = list(map(int,input().split()))
scr.sort()
scr.reverse()
ans = [0 for _ in range(n)]
ans[0] = scr[0]
pin = 1
while now:
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if ans[y] == 0:
        ans[y] = scr[pin]
        pin += 1
        now.append(y)
print(sum(scr[1:]))
print(' '.join(list(map(str,ans))))