n=int(input())
e=[[i] for i in range(n+1)]
for _ in range(n-1):
  a,b=map(int,input().split())
  e[a]+=[b]
  e[b]+=[a]
c=sorted(list(map(int,input().split())))
q=[1]
vis=[0]*(n+1)
ans=0
while q:
  now=q.pop()
  vis[now]=c.pop()
  for to in e[now]:
    if vis[to]:continue
    q+=[to]
print(sum(vis[2:]))
print(*vis[1:]) n=int(input()) n int(input()) int input() input [i] 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) [i] i e=[[i] for i in range(n+1)] e [[i] for i in range(n+1)] for _ in range(n-1):
  a,b=map(int,input().split())
  e[a]+=[b]
  e[b]+=[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 e[a]+=[b] e[a] e a [b] b e[b]+=[a] e[b] e b [a] a c=sorted(list(map(int,input().split()))) c sorted(list(map(int,input().split()))) sorted list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split q=[1] q [1] 1 vis=[0]*(n+1) vis [0]*(n+1) [0] 0 n+1 n 1 ans=0 ans 0 while q:
  now=q.pop()
  vis[now]=c.pop()
  for to in e[now]:
    if vis[to]:continue
    q+=[to] q now=q.pop() now q.pop() q.pop q pop vis[now]=c.pop() vis[now] vis now c.pop() c.pop c pop for to in e[now]:
    if vis[to]:continue
    q+=[to] to e[now] e now if vis[to]:continue
     vis[to] vis to q+=[to] q [to] to print(sum(vis[2:])) print sum(vis[2:]) sum vis[2:] vis 2: 2 print(*vis[1:]) print *vis[1:] vis[1:] vis 1: 1 e=[[i] for i in range(n+1)] [[i] for i in range(n+1)] e q=[1] [1] q q+=[to] [to] q ans=0 0 ans b=map(int,input().split()) map(int,input().split()) b c=sorted(list(map(int,input().split()))) sorted(list(map(int,input().split()))) c a,b=map(int,input().split()) map(int,input().split()) a now=q.pop() q.pop() now vis=[0]*(n+1) [0]*(n+1) vis n=int(input()) int(input()) n
n=int(input())
e=[[i] for i in range(n+1)]
for _ in range(n-1):
  a,b=map(int,input().split())
  e[a]+=[b]
  e[b]+=[a]
c=sorted(list(map(int,input().split())))
q=[1]
vis=[0]*(n+1)
ans=0
while q:
  now=q.pop()
  vis[now]=c.pop()
  for to in e[now]:
    if vis[to]:continue
    q+=[to]
print(sum(vis[2:]))
print(*vis[1:])