n=int(input())
a=[[]for i in range(n+1)]
for i in range(n-1):
    b,c=map(int,input().split())
    a[b].append(c)
    a[c].append(b)
b=[1]
c=[1]
l=[0]*(n+1)
l[1]=1
while len(b)>0:
    d=[]
    for i in b:
        for j in a[i]:
            if l[j]==0:
                d.append(j)
                c.append(j)
                l[j]=1
    b=d[:]
c=c[::-1]
e=sorted(list(map(int,input().split())))
b=[0]*n
for i in range(n):
    b[c[i]-1]=e[i]
print(sum(e[:-1]))
print(*b) n=int(input()) n int(input()) int input() input []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) [] a=[[]for i in range(n+1)] a [[]for i in range(n+1)] for i in range(n-1):
    b,c=map(int,input().split())
    a[b].append(c)
    a[c].append(b) i range(n-1) range n-1 n 1 b,c=map(int,input().split()) b map(int,input().split()) map int input().split() ().split () input split c a[b].append(c) [b].append [b] a b append c a[c].append(b) [c].append [c] a c append b b=[1] b [1] 1 c=[1] c [1] 1 l=[0]*(n+1) l [0]*(n+1) [0] 0 n+1 n 1 l[1]=1 l[1] l 1 1 while len(b)>0:
    d=[]
    for i in b:
        for j in a[i]:
            if l[j]==0:
                d.append(j)
                c.append(j)
                l[j]=1
    b=d[:] len(b)>0 len(b) len b 0 d=[] d [] for i in b:
        for j in a[i]:
            if l[j]==0:
                d.append(j)
                c.append(j)
                l[j]=1
     i b for j in a[i]:
            if l[j]==0:
                d.append(j)
                c.append(j)
                l[j]=1
     j a[i] a i if l[j]==0:
                d.append(j)
                c.append(j)
                l[j]=1
     l[j]==0 l[j] l j 0 d.append(j) d.append d append j c.append(j) c.append c append j l[j]=1 l[j] l j 1 b=d[:] b d[:] d : c=c[::-1] c c[::-1] c ::-1 -1 e=sorted(list(map(int,input().split()))) e sorted(list(map(int,input().split()))) sorted list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split b=[0]*n b [0]*n [0] 0 n for i in range(n):
    b[c[i]-1]=e[i] i range(n) range n b[c[i]-1]=e[i] b[c[i]-1] b c[i]-1 c[i] c i 1 e[i] e i print(sum(e[:-1])) print sum(e[:-1]) sum e[:-1] e :-1 -1 print(*b) print *b b c=[1] [1] c c=c[::-1] c[::-1] c b,c=map(int,input().split()) map(int,input().split()) b c=map(int,input().split()) map(int,input().split()) c d=[] [] d n=int(input()) int(input()) n b=d[:] d[:] b b=[0]*n [0]*n b l=[0]*(n+1) [0]*(n+1) l b=[1] [1] b e=sorted(list(map(int,input().split()))) sorted(list(map(int,input().split()))) e a=[[]for i in range(n+1)] [[]for i in range(n+1)] a
n=int(input())
a=[[]for i in range(n+1)]
for i in range(n-1):
    b,c=map(int,input().split())
    a[b].append(c)
    a[c].append(b)
b=[1]
c=[1]
l=[0]*(n+1)
l[1]=1
while len(b)>0:
    d=[]
    for i in b:
        for j in a[i]:
            if l[j]==0:
                d.append(j)
                c.append(j)
                l[j]=1
    b=d[:]
c=c[::-1]
e=sorted(list(map(int,input().split())))
b=[0]*n
for i in range(n):
    b[c[i]-1]=e[i]
print(sum(e[:-1]))
print(*b)