n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)
c=list(map(int,input().split()))
c.sort()
c.reverse()

def bfs(v):
  ans=[-1]*n
  ans[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        ct+=1
        ans[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return ans

ans=bfs(0)
print(sum(c)-c[0])
for i in range(n):
  ans[i]=str(c[ans[i]])
print(' '.join(ans)) n=int(input()) n int(input()) int input() input list(map(int,input().split())) 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) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split l=[list(map(int,input().split())) for i in range(n-1)] l [list(map(int,input().split())) for i in range(n-1)] [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] connection=[[] for i in range(n)] connection [[] for i in range(n)] for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1) i range(n-1) range n-1 n 1 connection[l[i][0]-1].append(l[i][1]-1) [l[i][0]-1].append [l[i][0]-1] connection l[i][0]-1 l[i][0] [i] l i 0 1 append l[i][1]-1 l[i][1] [i] l i 1 1 connection[l[i][1]-1].append(l[i][0]-1) [l[i][1]-1].append [l[i][1]-1] connection l[i][1]-1 l[i][1] [i] l i 1 1 append l[i][0]-1 l[i][0] [i] l i 0 1 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 c.reverse() c.reverse c reverse def bfs(v):
  ans=[-1]*n
  ans[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        ct+=1
        ans[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return ans bfs ans=[-1]*n ans [-1]*n [-1] -1 n ans[v]=0 ans[v] ans v 0 next=connection[v] next connection[v] connection v next2=set() next2 set() set visited=[-1]*n visited [-1]*n [-1] -1 n visited[v]=1 visited[v] visited v 1 visitct=1 visitct 1 ct=0 ct 0 while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        ct+=1
        ans[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
   len(next)!=0 and visitct!=n len(next)!=0 len(next) len next 0 visitct!=n visitct n for i in range(len(next)):
      if visited[next[i]]==-1:
        ct+=1
        ans[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
     i range(len(next)) range len(next) len next if visited[next[i]]==-1:
        ct+=1
        ans[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
     visited[next[i]]==-1 visited[next[i]] visited next[i] next i -1 ct+=1 ct 1 ans[next[i]]=ct ans[next[i]] ans next[i] next i ct visited[next[i]]=1 visited[next[i]] visited next[i] next i 1 visitct+=1 visitct 1 for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
     j range(len(connection[next[i]])) range len(connection[next[i]]) len connection[next[i]] connection next[i] next i if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
     visited[connection[next[i]][j]]==-1 visited[connection[next[i]][j]] visited connection[next[i]][j] [next[i]] connection next[i] next i j -1 next2.add(connection[next[i]][j]) next2.add next2 add connection[next[i]][j] [next[i]] connection next[i] next i j next=list(next2) next list(next2) list next2 next2=set() next2 set() set return ans ans v v ans=bfs(0) ans bfs(0) bfs 0 print(sum(c)-c[0]) print sum(c)-c[0] sum(c) sum c c[0] c 0 for i in range(n):
  ans[i]=str(c[ans[i]]) i range(n) range n ans[i]=str(c[ans[i]]) ans[i] ans i str(c[ans[i]]) str c[ans[i]] c ans[i] ans i print(' '.join(ans)) print ' '.join(ans) ' '.join ' ' join ans n=int(input()) int(input()) n def bfs(v):
  ans=[-1]*n
  ans[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        ct+=1
        ans[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return ans def bfs(v):
  ans=[-1]*n
  ans[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        ct+=1
        ans[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return ans bfs ans=bfs(0) bfs(0) ans l=[list(map(int,input().split())) for i in range(n-1)] [list(map(int,input().split())) for i in range(n-1)] l connection=[[] for i in range(n)] [[] for i in range(n)] connection c=list(map(int,input().split())) list(map(int,input().split())) c
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)
c=list(map(int,input().split()))
c.sort()
c.reverse()

def bfs(v):
  ans=[-1]*n
  ans[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        ct+=1
        ans[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return ans

ans=bfs(0)
print(sum(c)-c[0])
for i in range(n):
  ans[i]=str(c[ans[i]])
print(' '.join(ans))