n = int(input())
edge = [ [ int(v)-1 for v in input().split() ] for i in range(n-1) ]
num_list = sorted([ int(v) for v in input().split() ])
parent_list = [ None for i in range(n) ]
connect_list = [ [] for i in range(n) ]

for a, b in edge:
    connect_list[a].append(b)
    connect_list[b].append(a)

connect_point = [ len(i) for i in connect_list ]
p = connect_point.index(max(connect_point))

depth_list = [[p]]
search_list = [p]
parent_list[p] = -1

while search_list:
    new_search_list = []
    for i in search_list:
        for j in connect_list[i]:
            if parent_list[j] is None:
                parent_list[j] = i
                new_search_list.append(j)
    if new_search_list:
        depth_list.append(new_search_list)
    search_list = new_search_list

node = [ None for i in range(n) ]
q = 0

for i in depth_list[::-1]:
    for j in i:
        node[j] = num_list[q]
        q += 1

print(sum(num_list[:-1]))
print(*node) n = int(input()) n int(input()) int input() input [ int(v)-1 for v in input().split() ] for i in range(n-1) for i in range(n-1) i range(n-1) range n-1 n 1 for i in range(n-1) [ int(v)-1 for v in input().split() ] edge = [ [ int(v)-1 for v in input().split() ] for i in range(n-1) ] edge [ [ int(v)-1 for v in input().split() ] for i in range(n-1) ] int(v) for v in input().split() for v in input().split() v input().split() ().split () input split for v in input().split() int(v) int v num_list = sorted([ int(v) for v in input().split() ]) num_list sorted([ int(v) for v in input().split() ]) sorted [ int(v) for v in input().split() ] None for i in range(n) for i in range(n) i range(n) range n for i in range(n) None parent_list = [ None for i in range(n) ] parent_list [ None for i in range(n) ] [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] connect_list = [ [] for i in range(n) ] connect_list [ [] for i in range(n) ] for a, b in edge:
    connect_list[a].append(b)
    connect_list[b].append(a) a b edge connect_list[a].append(b) [a].append [a] connect_list a append b connect_list[b].append(a) [b].append [b] connect_list b append a len(i) for i in connect_list for i in connect_list i connect_list for i in connect_list len(i) len i connect_point = [ len(i) for i in connect_list ] connect_point [ len(i) for i in connect_list ] p = connect_point.index(max(connect_point)) p connect_point.index(max(connect_point)) connect_point.index connect_point index max(connect_point) max connect_point depth_list = [[p]] depth_list [[p]] [p] p search_list = [p] search_list [p] p parent_list[p] = -1 parent_list[p] parent_list p -1 while search_list:
    new_search_list = []
    for i in search_list:
        for j in connect_list[i]:
            if parent_list[j] is None:
                parent_list[j] = i
                new_search_list.append(j)
    if new_search_list:
        depth_list.append(new_search_list)
    search_list = new_search_list search_list new_search_list = [] new_search_list [] for i in search_list:
        for j in connect_list[i]:
            if parent_list[j] is None:
                parent_list[j] = i
                new_search_list.append(j)
     i search_list for j in connect_list[i]:
            if parent_list[j] is None:
                parent_list[j] = i
                new_search_list.append(j)
     j connect_list[i] connect_list i if parent_list[j] is None:
                parent_list[j] = i
                new_search_list.append(j)
     parent_list[j] is None parent_list[j] parent_list j None parent_list[j] = i parent_list[j] parent_list j i new_search_list.append(j) new_search_list.append new_search_list append j if new_search_list:
        depth_list.append(new_search_list)
     new_search_list depth_list.append(new_search_list) depth_list.append depth_list append new_search_list search_list = new_search_list search_list new_search_list None for i in range(n) for i in range(n) i range(n) range n for i in range(n) None node = [ None for i in range(n) ] node [ None for i in range(n) ] q = 0 q 0 for i in depth_list[::-1]:
    for j in i:
        node[j] = num_list[q]
        q += 1 i depth_list[::-1] depth_list ::-1 -1 for j in i:
        node[j] = num_list[q]
        q += 1 j i node[j] = num_list[q] node[j] node j num_list[q] num_list q q += 1 q 1 print(sum(num_list[:-1])) print sum(num_list[:-1]) sum num_list[:-1] num_list :-1 -1 print(*node) print *node node edge = [ [ int(v)-1 for v in input().split() ] for i in range(n-1) ] [ [ int(v)-1 for v in input().split() ] for i in range(n-1) ] edge new_search_list = [] [] new_search_list p = connect_point.index(max(connect_point)) connect_point.index(max(connect_point)) p parent_list = [ None for i in range(n) ] [ None for i in range(n) ] parent_list connect_point = [ len(i) for i in connect_list ] [ len(i) for i in connect_list ] connect_point q += 1 1 q depth_list = [[p]] [[p]] depth_list num_list = sorted([ int(v) for v in input().split() ]) sorted([ int(v) for v in input().split() ]) num_list search_list = new_search_list new_search_list search_list connect_list = [ [] for i in range(n) ] [ [] for i in range(n) ] connect_list search_list = [p] [p] search_list node = [ None for i in range(n) ] [ None for i in range(n) ] node n = int(input()) int(input()) n q = 0 0 q
n = int(input())
edge = [ [ int(v)-1 for v in input().split() ] for i in range(n-1) ]
num_list = sorted([ int(v) for v in input().split() ])
parent_list = [ None for i in range(n) ]
connect_list = [ [] for i in range(n) ]

for a, b in edge:
    connect_list[a].append(b)
    connect_list[b].append(a)

connect_point = [ len(i) for i in connect_list ]
p = connect_point.index(max(connect_point))

depth_list = [[p]]
search_list = [p]
parent_list[p] = -1

while search_list:
    new_search_list = []
    for i in search_list:
        for j in connect_list[i]:
            if parent_list[j] is None:
                parent_list[j] = i
                new_search_list.append(j)
    if new_search_list:
        depth_list.append(new_search_list)
    search_list = new_search_list

node = [ None for i in range(n) ]
q = 0

for i in depth_list[::-1]:
    for j in i:
        node[j] = num_list[q]
        q += 1

print(sum(num_list[:-1]))
print(*node)