#%%
n = int(input())
a, b = [0] * (n-1), [0] * (n-1)
reach = [[] for _ in range(n)]
for i in range(n-1):
    a[i], b[i] = map(int, input().split())
    reach[a[i]-1].append(b[i]-1)
    reach[b[i]-1].append(a[i]-1)
c = list(map(int, input().split()))
c.sort(reverse=True)
ans_list = [0] * n
check = [0] * n

stack = [0]
j = 0

while len(stack) > 0: 
    tmp = stack.pop(-1)
    check[tmp] = 1
    ans_list[tmp] = str(c[j])
    j += 1
    for i in range(len(reach[tmp])):
        if check[reach[tmp][i]] == 0:
            stack.append(reach[tmp][i])
        else:
            pass
    
print(sum(c) - max(c))
print(' '.join(ans_list)) n = int(input()) n int(input()) int input() input a, b = [0] * (n-1), [0] * (n-1) a [0] * (n-1) [0] 0 n-1 n 1 b [0] * (n-1) [0] 0 n-1 n 1 [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] reach = [[] for _ in range(n)] reach [[] for _ in range(n)] for i in range(n-1):
    a[i], b[i] = map(int, input().split())
    reach[a[i]-1].append(b[i]-1)
    reach[b[i]-1].append(a[i]-1) i range(n-1) range n-1 n 1 a[i], b[i] = map(int, input().split()) a[i] a i map(int, input().split()) map int input().split() ().split () input split b[i] b i reach[a[i]-1].append(b[i]-1) [a[i]-1].append [a[i]-1] reach a[i]-1 a[i] a i 1 append b[i]-1 b[i] b i 1 reach[b[i]-1].append(a[i]-1) [b[i]-1].append [b[i]-1] reach b[i]-1 b[i] b i 1 append a[i]-1 a[i] a i 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 ans_list = [0] * n ans_list [0] * n [0] 0 n check = [0] * n check [0] * n [0] 0 n stack = [0] stack [0] 0 j = 0 j 0 while len(stack) > 0: 
    tmp = stack.pop(-1)
    check[tmp] = 1
    ans_list[tmp] = str(c[j])
    j += 1
    for i in range(len(reach[tmp])):
        if check[reach[tmp][i]] == 0:
            stack.append(reach[tmp][i])
        else:
            pass
     len(stack) > 0 len(stack) len stack 0 tmp = stack.pop(-1) tmp stack.pop(-1) stack.pop stack pop -1 check[tmp] = 1 check[tmp] check tmp 1 ans_list[tmp] = str(c[j]) ans_list[tmp] ans_list tmp str(c[j]) str c[j] c j j += 1 j 1 for i in range(len(reach[tmp])):
        if check[reach[tmp][i]] == 0:
            stack.append(reach[tmp][i])
        else:
            pass
     i range(len(reach[tmp])) range len(reach[tmp]) len reach[tmp] reach tmp if check[reach[tmp][i]] == 0:
            stack.append(reach[tmp][i])
        else:
            pass
     check[reach[tmp][i]] == 0 check[reach[tmp][i]] check reach[tmp][i] [tmp] reach tmp i 0 stack.append(reach[tmp][i]) stack.append stack append reach[tmp][i] [tmp] reach tmp i print(sum(c) - max(c)) print sum(c) - max(c) sum(c) sum c max(c) max c print(' '.join(ans_list)) print ' '.join(ans_list) ' '.join ' ' join ans_list b = [0] * (n-1), [0] * (n-1) [0] * (n-1) b ans_list = [0] * n [0] * n ans_list check = [0] * n [0] * n check tmp = stack.pop(-1) stack.pop(-1) tmp j = 0 0 j c = list(map(int, input().split())) list(map(int, input().split())) c reach = [[] for _ in range(n)] [[] for _ in range(n)] reach stack = [0] [0] stack a, b = [0] * (n-1), [0] * (n-1) [0] * (n-1) a n = int(input()) int(input()) n j += 1 1 j
#%%
n = int(input())
a, b = [0] * (n-1), [0] * (n-1)
reach = [[] for _ in range(n)]
for i in range(n-1):
    a[i], b[i] = map(int, input().split())
    reach[a[i]-1].append(b[i]-1)
    reach[b[i]-1].append(a[i]-1)
c = list(map(int, input().split()))
c.sort(reverse=True)
ans_list = [0] * n
check = [0] * n

stack = [0]
j = 0

while len(stack) > 0: 
    tmp = stack.pop(-1)
    check[tmp] = 1
    ans_list[tmp] = str(c[j])
    j += 1
    for i in range(len(reach[tmp])):
        if check[reach[tmp][i]] == 0:
            stack.append(reach[tmp][i])
        else:
            pass
    
print(sum(c) - max(c))
print(' '.join(ans_list))
