N = int(input())
L = [list(map(int,input().split())) for k in range(N-1)]
c = sorted(list(map(int,input().split())))
a = sum(c) - c[-1]
T = [[] for k in range(N)]
for e in L:
    T[e[0]-1].append(e[1]-1)
    T[e[1]-1].append(e[0]-1)

kyori = [-1 for k in range(N)]
que = [L[0][0]]
kyori[L[0][0]] = c.pop()

while len(que) > 0:
    now = que.pop()
    for tsugi in T[now]:
        if kyori[tsugi] == -1:
            kyori[tsugi] = c.pop()
            que.append(tsugi)
print(a)
print(*kyori, sep=" ") N = int(input()) N int(input()) int input() input list(map(int,input().split())) for k in range(N-1) for k in range(N-1) k range(N-1) range N-1 N 1 for k in range(N-1) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split L = [list(map(int,input().split())) for k in range(N-1)] L [list(map(int,input().split())) for k in range(N-1)] c = sorted(list(map(int,input().split()))) c sorted(list(map(int,input().split()))) sorted list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a = sum(c) - c[-1] a sum(c) - c[-1] sum(c) sum c c[-1] c -1 [] for k in range(N) for k in range(N) k range(N) range N for k in range(N) [] T = [[] for k in range(N)] T [[] for k in range(N)] for e in L:
    T[e[0]-1].append(e[1]-1)
    T[e[1]-1].append(e[0]-1) e L T[e[0]-1].append(e[1]-1) [e[0]-1].append [e[0]-1] T e[0]-1 e[0] e 0 1 append e[1]-1 e[1] e 1 1 T[e[1]-1].append(e[0]-1) [e[1]-1].append [e[1]-1] T e[1]-1 e[1] e 1 1 append e[0]-1 e[0] e 0 1 -1 for k in range(N) for k in range(N) k range(N) range N for k in range(N) -1 kyori = [-1 for k in range(N)] kyori [-1 for k in range(N)] que = [L[0][0]] que [L[0][0]] L[0][0] [0] L 0 0 kyori[L[0][0]] = c.pop() kyori[L[0][0]] kyori L[0][0] [0] L 0 0 c.pop() c.pop c pop while len(que) > 0:
    now = que.pop()
    for tsugi in T[now]:
        if kyori[tsugi] == -1:
            kyori[tsugi] = c.pop()
            que.append(tsugi) len(que) > 0 len(que) len que 0 now = que.pop() now que.pop() que.pop que pop for tsugi in T[now]:
        if kyori[tsugi] == -1:
            kyori[tsugi] = c.pop()
            que.append(tsugi) tsugi T[now] T now if kyori[tsugi] == -1:
            kyori[tsugi] = c.pop()
            que.append(tsugi) kyori[tsugi] == -1 kyori[tsugi] kyori tsugi -1 kyori[tsugi] = c.pop() kyori[tsugi] kyori tsugi c.pop() c.pop c pop que.append(tsugi) que.append que append tsugi print(a) print a print(*kyori, sep=" ") print *kyori kyori sep=" " sep " " que = [L[0][0]] [L[0][0]] que N = int(input()) int(input()) N c = sorted(list(map(int,input().split()))) sorted(list(map(int,input().split()))) c L = [list(map(int,input().split())) for k in range(N-1)] [list(map(int,input().split())) for k in range(N-1)] L T = [[] for k in range(N)] [[] for k in range(N)] T now = que.pop() que.pop() now a = sum(c) - c[-1] sum(c) - c[-1] a kyori = [-1 for k in range(N)] [-1 for k in range(N)] kyori
N = int(input())
L = [list(map(int,input().split())) for k in range(N-1)]
c = sorted(list(map(int,input().split())))
a = sum(c) - c[-1]
T = [[] for k in range(N)]
for e in L:
    T[e[0]-1].append(e[1]-1)
    T[e[1]-1].append(e[0]-1)

kyori = [-1 for k in range(N)]
que = [L[0][0]]
kyori[L[0][0]] = c.pop()

while len(que) > 0:
    now = que.pop()
    for tsugi in T[now]:
        if kyori[tsugi] == -1:
            kyori[tsugi] = c.pop()
            que.append(tsugi)
print(a)
print(*kyori, sep=" ")
