n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])
q=[1]
f=q*-~n
e=[[]for _ in f]
for a,b in zip(t[:-n:2],t[1:-n:2]):e[a]+=b,;e[b]+=a,
while q:
 v=q.pop();n-=1;f[v]=c[n]
 for w in e[v]:q+=[w]*(f[w]<2)
print(sum(c[:-1]),*f[1:]) n,*t=map(int,open(0).read().split()) n map(int,open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split *t t c=sorted(t[-n:]) c sorted(t[-n:]) sorted t[-n:] t -n: -n n q=[1] q [1] 1 f=q*-~n f q*-~n q -~n ~n n []for _ in f for _ in f _ f for _ in f [] e=[[]for _ in f] e [[]for _ in f] for a,b in zip(t[:-n:2],t[1:-n:2]):e[a]+=b,;e[b]+=a, a b zip(t[:-n:2],t[1:-n:2]) zip t[:-n:2] t :-n:2 -n n 2 t[1:-n:2] t 1:-n:2 1 -n n 2 while q:
 v=q.pop();n-=1;f[v]=c[n]
 for w in e[v]:q+=[w]*(f[w]<2) q v=q.pop() v q.pop() q.pop q pop n-=1 n 1 f[v]=c[n] f[v] f v c[n] c n for w in e[v]:q+=[w]*(f[w]<2 w e[v] e v print(sum(c[:-1]),*f[1:]) print sum(c[:-1]) sum c[:-1] c :-1 -1 *f[1:] f[1:] f 1: 1 n,*t=map(int,open(0).read().split()) map(int,open(0).read().split()) n n-=1 1 n q=[1] [1] q f=q*-~n q*-~n f e=[[]for _ in f] [[]for _ in f] e c=sorted(t[-n:]) sorted(t[-n:]) c v=q.pop() q.pop() v
n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])
q=[1]
f=q*-~n
e=[[]for _ in f]
for a,b in zip(t[:-n:2],t[1:-n:2]):e[a]+=b,;e[b]+=a,
while q:
 v=q.pop();n-=1;f[v]=c[n]
 for w in e[v]:q+=[w]*(f[w]<2)
print(sum(c[:-1]),*f[1:])