n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])
q=[1]
f=q*n
e=[[]for _ in f+q]
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-1]=c[n];q+=[w for w in e[v]if f[w-1]<2]
print(sum(c[:-1]),*f) 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 []for _ in f+q for _ in f+q _ f+q f q for _ in f+q [] e=[[]for _ in f+q] e [[]for _ in f+q] 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 w for w in e[v]if f[w-1]<2 for w in e[v]if f[w-1]<2 w e[v] e v f[w-1]<2 f[w-1] f w-1 w 1 2 if f[w-1]<2 w while q:v=q.pop();n-=1;f[v-1]=c[n];q+=[w for w in e[v]if f[w-1]<2] q print(sum(c[:-1]),*f) print sum(c[:-1]) sum c[:-1] c :-1 -1 *f f q=[1] [1] q f=q*n q*n f n,*t=map(int,open(0).read().split()) map(int,open(0).read().split()) n c=sorted(t[-n:]) sorted(t[-n:]) c e=[[]for _ in f+q] [[]for _ in f+q] e
n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])
q=[1]
f=q*n
e=[[]for _ in f+q]
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-1]=c[n];q+=[w for w in e[v]if f[w-1]<2]
print(sum(c[:-1]),*f)