N = int(input())
from collections import deque
e = []
for i in range(N-1):
    a,b = map(int,input().split())
    e.append((min(a,b)-1,max(a,b)-1))
e.sort()
e = deque(e)
c = list(map(int,input().split()))
c.sort()
print(sum(c)-c[-1])

d = [0]*N
d[0] = str(c.pop())
while e:
    a,b = e.popleft()
    if d[a] != 0 and d[b] == 0:
        d[b] = str(c.pop())
    elif d[a] == 0 and d[b] != 0:
        d[a] = str(c.pop())
    else:
        e.append((a,b))

print(' '.join(d)) N = int(input()) N int(input()) int input() input from collections import deque e = [] e [] for i in range(N-1):
    a,b = map(int,input().split())
    e.append((min(a,b)-1,max(a,b)-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 e.append((min(a,b)-1,max(a,b)-1)) e.append e append (min(a,b)-1,max(a,b)-1) min(a,b)-1 min(a,b) min a b 1 max(a,b)-1 max(a,b) max a b 1 e.sort() e.sort e sort e = deque(e) e deque(e) deque e 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() c.sort c sort print(sum(c)-c[-1]) print sum(c)-c[-1] sum(c) sum c c[-1] c -1 d = [0]*N d [0]*N [0] 0 N d[0] = str(c.pop()) d[0] d 0 str(c.pop()) str c.pop() c.pop c pop while e:
    a,b = e.popleft()
    if d[a] != 0 and d[b] == 0:
        d[b] = str(c.pop())
    elif d[a] == 0 and d[b] != 0:
        d[a] = str(c.pop())
    else:
        e.append((a,b)) e a,b = e.popleft() a e.popleft() e.popleft e popleft b if d[a] != 0 and d[b] == 0:
        d[b] = str(c.pop())
    elif d[a] == 0 and d[b] != 0:
        d[a] = str(c.pop())
    else:
        e.append((a,b)) d[a] != 0 and d[b] == 0 d[a] != 0 d[a] d a 0 d[b] == 0 d[b] d b 0 d[b] = str(c.pop()) d[b] d b str(c.pop()) str c.pop() c.pop c pop elif d[a] == 0 and d[b] != 0:
        d[a] = str(c.pop())
     d[a] == 0 and d[b] != 0 d[a] == 0 d[a] d a 0 d[b] != 0 d[b] d b 0 d[a] = str(c.pop()) d[a] d a str(c.pop()) str c.pop() c.pop c pop e.append((a,b)) e.append e append (a,b) a b print(' '.join(d)) print ' '.join(d) ' '.join ' ' join d e = [] [] e a,b = e.popleft() e.popleft() a d = [0]*N [0]*N d b = e.popleft() e.popleft() b c = list(map(int,input().split())) list(map(int,input().split())) c N = int(input()) int(input()) N e = deque(e) deque(e) e a,b = map(int,input().split()) map(int,input().split()) a b = map(int,input().split()) map(int,input().split()) b
N = int(input())
from collections import deque
e = []
for i in range(N-1):
    a,b = map(int,input().split())
    e.append((min(a,b)-1,max(a,b)-1))
e.sort()
e = deque(e)
c = list(map(int,input().split()))
c.sort()
print(sum(c)-c[-1])

d = [0]*N
d[0] = str(c.pop())
while e:
    a,b = e.popleft()
    if d[a] != 0 and d[b] == 0:
        d[b] = str(c.pop())
    elif d[a] == 0 and d[b] != 0:
        d[a] = str(c.pop())
    else:
        e.append((a,b))

print(' '.join(d))