N = int(input())
import collections

Ls = [collections.deque() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    Ls[a - 1].append(b - 1)
    Ls[b - 1].append(a - 1)

Cs = sorted(map(int, input().split()), reverse=True)
print(sum(Cs) - Cs[0])

sw = [-1] * N
sw[0] = Cs[0]
ct = 1
stk = collections.deque()
stk.appendleft(0)
while len(stk) > 0:
    crN = stk[0]
    if len(Ls[crN]) == 0:
        stk.popleft()
        continue
    nxN = Ls[crN].popleft()
    if sw[nxN] > 0:
        continue
    sw[nxN] = Cs[ct]
    ct += 1
    stk.append(nxN)
print(" ".join(map(str, sw))) N = int(input()) N int(input()) int input() input import collections collections collections.deque() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) collections.deque() collections.deque collections deque Ls = [collections.deque() for _ in range(N)] Ls [collections.deque() for _ in range(N)] for _ in range(N - 1):
    a, b = map(int, input().split())
    Ls[a - 1].append(b - 1)
    Ls[b - 1].append(a - 1) _ 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 Ls[a - 1].append(b - 1) [a - 1].append [a - 1] Ls a - 1 a 1 append b - 1 b 1 Ls[b - 1].append(a - 1) [b - 1].append [b - 1] Ls b - 1 b 1 append a - 1 a 1 Cs = sorted(map(int, input().split()), reverse=True) Cs sorted(map(int, input().split()), reverse=True) sorted map(int, input().split()) map int input().split() ().split () input split reverse=True reverse True print(sum(Cs) - Cs[0]) print sum(Cs) - Cs[0] sum(Cs) sum Cs Cs[0] Cs 0 sw = [-1] * N sw [-1] * N [-1] -1 N sw[0] = Cs[0] sw[0] sw 0 Cs[0] Cs 0 ct = 1 ct 1 stk = collections.deque() stk collections.deque() collections.deque collections deque stk.appendleft(0) stk.appendleft stk appendleft 0 while len(stk) > 0:
    crN = stk[0]
    if len(Ls[crN]) == 0:
        stk.popleft()
        continue
    nxN = Ls[crN].popleft()
    if sw[nxN] > 0:
        continue
    sw[nxN] = Cs[ct]
    ct += 1
    stk.append(nxN) len(stk) > 0 len(stk) len stk 0 crN = stk[0] crN stk[0] stk 0 if len(Ls[crN]) == 0:
        stk.popleft()
        continue
     len(Ls[crN]) == 0 len(Ls[crN]) len Ls[crN] Ls crN 0 stk.popleft() stk.popleft stk popleft continue nxN = Ls[crN].popleft() nxN Ls[crN].popleft() [crN].popleft [crN] Ls crN popleft if sw[nxN] > 0:
        continue
     sw[nxN] > 0 sw[nxN] sw nxN 0 continue sw[nxN] = Cs[ct] sw[nxN] sw nxN Cs[ct] Cs ct ct += 1 ct 1 stk.append(nxN) stk.append stk append nxN print(" ".join(map(str, sw))) print " ".join(map(str, sw)) " ".join " " join map(str, sw) map str sw ct = 1 1 ct N = int(input()) int(input()) N Cs = sorted(map(int, input().split()), reverse=True) sorted(map(int, input().split()), reverse=True) Cs sw = [-1] * N [-1] * N sw ct += 1 1 ct Ls = [collections.deque() for _ in range(N)] [collections.deque() for _ in range(N)] Ls a, b = map(int, input().split()) map(int, input().split()) a stk = collections.deque() collections.deque() stk crN = stk[0] stk[0] crN b = map(int, input().split()) map(int, input().split()) b nxN = Ls[crN].popleft() Ls[crN].popleft() nxN
N = int(input())
import collections

Ls = [collections.deque() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    Ls[a - 1].append(b - 1)
    Ls[b - 1].append(a - 1)

Cs = sorted(map(int, input().split()), reverse=True)
print(sum(Cs) - Cs[0])

sw = [-1] * N
sw[0] = Cs[0]
ct = 1
stk = collections.deque()
stk.appendleft(0)
while len(stk) > 0:
    crN = stk[0]
    if len(Ls[crN]) == 0:
        stk.popleft()
        continue
    nxN = Ls[crN].popleft()
    if sw[nxN] > 0:
        continue
    sw[nxN] = Cs[ct]
    ct += 1
    stk.append(nxN)
print(" ".join(map(str, sw)))