n=int(input())
g=[[] for i in range(n)]
ro=[0]*n
for i in range(n-1):
    a,b=map(int,input().split())
    ro[a-1]+=1
    ro[b-1]+=1
    g[a-1].append(b-1)
    g[b-1].append(a-1)
c=list(map(int,input().split()))
c.sort(reverse=True)
m=max(ro)
mi=ro.index(m)
q=[mi]
ans=[0]*n
v=[0]*n
v[mi]=1
ans[mi]=c.pop(0)
while len(q)>0:
    s=q.pop()
    for i in g[s]:
        if v[i]==0:
            v[i]=1
            ans[i]=c.pop(0)
            q.append(i)
print(sum(ans)-max(ans))
print(*ans) n=int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] g=[[] for i in range(n)] g [[] for i in range(n)] ro=[0]*n ro [0]*n [0] 0 n for i in range(n-1):
    a,b=map(int,input().split())
    ro[a-1]+=1
    ro[b-1]+=1
    g[a-1].append(b-1)
    g[b-1].append(a-1) i 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 ro[a-1]+=1 ro[a-1] ro a-1 a 1 1 ro[b-1]+=1 ro[b-1] ro b-1 b 1 1 g[a-1].append(b-1) [a-1].append [a-1] g a-1 a 1 append b-1 b 1 g[b-1].append(a-1) [b-1].append [b-1] g b-1 b 1 append a-1 a 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(reverse=True) c.sort c sort reverse=True reverse True m=max(ro) m max(ro) max ro mi=ro.index(m) mi ro.index(m) ro.index ro index m q=[mi] q [mi] mi ans=[0]*n ans [0]*n [0] 0 n v=[0]*n v [0]*n [0] 0 n v[mi]=1 v[mi] v mi 1 ans[mi]=c.pop(0) ans[mi] ans mi c.pop(0) c.pop c pop 0 while len(q)>0:
    s=q.pop()
    for i in g[s]:
        if v[i]==0:
            v[i]=1
            ans[i]=c.pop(0)
            q.append(i) len(q)>0 len(q) len q 0 s=q.pop() s q.pop() q.pop q pop for i in g[s]:
        if v[i]==0:
            v[i]=1
            ans[i]=c.pop(0)
            q.append(i) i g[s] g s if v[i]==0:
            v[i]=1
            ans[i]=c.pop(0)
            q.append(i) v[i]==0 v[i] v i 0 v[i]=1 v[i] v i 1 ans[i]=c.pop(0) ans[i] ans i c.pop(0) c.pop c pop 0 q.append(i) q.append q append i print(sum(ans)-max(ans)) print sum(ans)-max(ans) sum(ans) sum ans max(ans) max ans print(*ans) print *ans ans n=int(input()) int(input()) n v=[0]*n [0]*n v g=[[] for i in range(n)] [[] for i in range(n)] g a,b=map(int,input().split()) map(int,input().split()) a c=list(map(int,input().split())) list(map(int,input().split())) c ro=[0]*n [0]*n ro s=q.pop() q.pop() s mi=ro.index(m) ro.index(m) mi q=[mi] [mi] q b=map(int,input().split()) map(int,input().split()) b ans=[0]*n [0]*n ans m=max(ro) max(ro) m
n=int(input())
g=[[] for i in range(n)]
ro=[0]*n
for i in range(n-1):
    a,b=map(int,input().split())
    ro[a-1]+=1
    ro[b-1]+=1
    g[a-1].append(b-1)
    g[b-1].append(a-1)
c=list(map(int,input().split()))
c.sort(reverse=True)
m=max(ro)
mi=ro.index(m)
q=[mi]
ans=[0]*n
v=[0]*n
v[mi]=1
ans[mi]=c.pop(0)
while len(q)>0:
    s=q.pop()
    for i in g[s]:
        if v[i]==0:
            v[i]=1
            ans[i]=c.pop(0)
            q.append(i)
print(sum(ans)-max(ans))
print(*ans)
