n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
c = [int(i) for i in input().split()]
c.sort()
c.reverse()
ans_list = [0 for _ in range(n)]
ans = 0
p_list = [0]
ans_list[0] = c.pop(0)
while len(p_list) > 0:
    p = p_list.pop(0)
    for g in graph[p]:
        if ans_list[g] == 0:
            ans_list[g] = c.pop(0)
            ans += ans_list[g]
            p_list.append(g)
print(ans)
print(' '.join([str(i) for i in ans_list])) 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) [] graph = [[] for _ in range(n)] graph [[] for _ in range(n)] for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a) _ 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 a -= 1 a 1 b -= 1 b 1 graph[a].append(b) [a].append [a] graph a append b graph[b].append(a) [b].append [b] graph b append a int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i c = [int(i) for i in input().split()] c [int(i) for i in input().split()] c.sort() c.sort c sort c.reverse() c.reverse c reverse 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 ans_list = [0 for _ in range(n)] ans_list [0 for _ in range(n)] ans = 0 ans 0 p_list = [0] p_list [0] 0 ans_list[0] = c.pop(0) ans_list[0] ans_list 0 c.pop(0) c.pop c pop 0 while len(p_list) > 0:
    p = p_list.pop(0)
    for g in graph[p]:
        if ans_list[g] == 0:
            ans_list[g] = c.pop(0)
            ans += ans_list[g]
            p_list.append(g) len(p_list) > 0 len(p_list) len p_list 0 p = p_list.pop(0) p p_list.pop(0) p_list.pop p_list pop 0 for g in graph[p]:
        if ans_list[g] == 0:
            ans_list[g] = c.pop(0)
            ans += ans_list[g]
            p_list.append(g) g graph[p] graph p if ans_list[g] == 0:
            ans_list[g] = c.pop(0)
            ans += ans_list[g]
            p_list.append(g) ans_list[g] == 0 ans_list[g] ans_list g 0 ans_list[g] = c.pop(0) ans_list[g] ans_list g c.pop(0) c.pop c pop 0 ans += ans_list[g] ans ans_list[g] ans_list g p_list.append(g) p_list.append p_list append g print(ans) print ans str(i) for i in ans_list for i in ans_list i ans_list for i in ans_list str(i) str i print(' '.join([str(i) for i in ans_list])) print ' '.join([str(i) for i in ans_list]) ' '.join ' ' join [str(i) for i in ans_list] graph = [[] for _ in range(n)] [[] for _ in range(n)] graph p_list = [0] [0] p_list p = p_list.pop(0) p_list.pop(0) p ans += ans_list[g] ans_list[g] ans a -= 1 1 a n = int(input()) int(input()) n a, b = map(int, input().split()) map(int, input().split()) a ans_list = [0 for _ in range(n)] [0 for _ in range(n)] ans_list b -= 1 1 b ans = 0 0 ans b = map(int, input().split()) map(int, input().split()) b c = [int(i) for i in input().split()] [int(i) for i in input().split()] c
n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
c = [int(i) for i in input().split()]
c.sort()
c.reverse()
ans_list = [0 for _ in range(n)]
ans = 0
p_list = [0]
ans_list[0] = c.pop(0)
while len(p_list) > 0:
    p = p_list.pop(0)
    for g in graph[p]:
        if ans_list[g] == 0:
            ans_list[g] = c.pop(0)
            ans += ans_list[g]
            p_list.append(g)
print(ans)
print(' '.join([str(i) for i in ans_list]))