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