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

C = list(map(int, input().split()))
C.sort(reverse=True)
D = [0 for _ in range(N)]
stack = es[0]
D[0] = C[0]
cnt_c = 1
while stack:
    new_stack = []
    for i in stack:
        if D[i] == 0:
            D[i] = C[cnt_c]
            cnt_c += 1
            new_stack.extend(es[i])
    if len(new_stack) == 0:
        break
    else:
        stack = new_stack

print(sum(D) - C[0]) # ｃの最大のやつは辺の値になれないので引く
print(*D) N = int(input()) N int(input()) int input() input [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] es = [[] for _ in range(N)] es [[] for _ in range(N)] for i in range(N-1):
    a,b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-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 es[a-1].append(b-1) [a-1].append [a-1] es a-1 a 1 append b-1 b 1 es[b-1].append(a-1) [b-1].append [b-1] es b-1 b 1 append a-1 a 1 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(reverse=True) C.sort C sort reverse=True reverse True 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 D = [0 for _ in range(N)] D [0 for _ in range(N)] stack = es[0] stack es[0] es 0 D[0] = C[0] D[0] D 0 C[0] C 0 cnt_c = 1 cnt_c 1 while stack:
    new_stack = []
    for i in stack:
        if D[i] == 0:
            D[i] = C[cnt_c]
            cnt_c += 1
            new_stack.extend(es[i])
    if len(new_stack) == 0:
        break
    else:
        stack = new_stack stack new_stack = [] new_stack [] for i in stack:
        if D[i] == 0:
            D[i] = C[cnt_c]
            cnt_c += 1
            new_stack.extend(es[i])
     i stack if D[i] == 0:
            D[i] = C[cnt_c]
            cnt_c += 1
            new_stack.extend(es[i])
     D[i] == 0 D[i] D i 0 D[i] = C[cnt_c] D[i] D i C[cnt_c] C cnt_c cnt_c += 1 cnt_c 1 new_stack.extend(es[i]) new_stack.extend new_stack extend es[i] es i if len(new_stack) == 0:
        break
    else:
        stack = new_stack len(new_stack) == 0 len(new_stack) len new_stack 0 break stack = new_stack stack new_stack print(sum(D) - C[0]) print sum(D) - C[0] sum(D) sum D C[0] C 0 print(*D) print *D D es = [[] for _ in range(N)] [[] for _ in range(N)] es stack = new_stack new_stack stack N = int(input()) int(input()) N stack = es[0] es[0] stack new_stack = [] [] new_stack D = [0 for _ in range(N)] [0 for _ in range(N)] D cnt_c += 1 1 cnt_c C = list(map(int, input().split())) list(map(int, input().split())) C cnt_c = 1 1 cnt_c a,b = map(int, input().split()) map(int, input().split()) a b = map(int, input().split()) map(int, input().split()) b
N = int(input())
es = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

C = list(map(int, input().split()))
C.sort(reverse=True)
D = [0 for _ in range(N)]
stack = es[0]
D[0] = C[0]
cnt_c = 1
while stack:
    new_stack = []
    for i in stack:
        if D[i] == 0:
            D[i] = C[cnt_c]
            cnt_c += 1
            new_stack.extend(es[i])
    if len(new_stack) == 0:
        break
    else:
        stack = new_stack

print(sum(D) - C[0]) # ｃの最大のやつは辺の値になれないので引く
print(*D)