import sys
sys.setrecursionlimit(10**9)

N = int(input())
edge = [[] for _ in range(N)]

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

C = list(map(int, input().split()))
C.sort(reverse=True)
nodes = [0] * N

#print(nodes)
cidx = -1
ans = []
def dfs(v, pv, w):
    global cidx
    cidx += 1
    nodes[v] = C[cidx]
    ans.append(min(w, C[cidx]))
    for nv in edge[v]:
        if pv == nv: continue
        dfs(nv, v, C[cidx])

dfs(0, 0, 0)
print(sum(ans))
print(*nodes, sep=" ") import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 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) [] edge = [[] for _ in range(N)] edge [[] for _ in range(N)] for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a) 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 a, b = a-1, b-1 a a-1 a 1 b b-1 b 1 edge[a].append(b) [a].append [a] edge a append b edge[b].append(a) [b].append [b] edge b append a 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 nodes = [0] * N nodes [0] * N [0] 0 N cidx = -1 cidx -1 ans = [] ans [] def dfs(v, pv, w):
    global cidx
    cidx += 1
    nodes[v] = C[cidx]
    ans.append(min(w, C[cidx]))
    for nv in edge[v]:
        if pv == nv: continue
        dfs(nv, v, C[cidx]) dfs global cidx cidx += 1 cidx 1 nodes[v] = C[cidx] nodes[v] nodes v C[cidx] C cidx ans.append(min(w, C[cidx])) ans.append ans append min(w, C[cidx]) min w C[cidx] C cidx for nv in edge[v]:
        if pv == nv: continue
        dfs(nv, v, C[cidx]) nv edge[v] edge v if pv == nv: continue
         pv == nv pv nv dfs(nv, v, C[cidx]) dfs nv v C[cidx] C cidx v v pv pv w w dfs(0, 0, 0) dfs 0 0 0 print(sum(ans)) print sum(ans) sum ans print(*nodes, sep=" ") print *nodes nodes sep=" " sep " " a, b = map(int, input().split()) map(int, input().split()) a cidx = -1 -1 cidx b = map(int, input().split()) map(int, input().split()) b b = a-1, b-1 b-1 b def dfs(v, pv, w):
    global cidx
    cidx += 1
    nodes[v] = C[cidx]
    ans.append(min(w, C[cidx]))
    for nv in edge[v]:
        if pv == nv: continue
        dfs(nv, v, C[cidx]) def dfs(v, pv, w):
    global cidx
    cidx += 1
    nodes[v] = C[cidx]
    ans.append(min(w, C[cidx]))
    for nv in edge[v]:
        if pv == nv: continue
        dfs(nv, v, C[cidx]) dfs a, b = a-1, b-1 a-1 a N = int(input()) int(input()) N C = list(map(int, input().split())) list(map(int, input().split())) C ans = [] [] ans edge = [[] for _ in range(N)] [[] for _ in range(N)] edge nodes = [0] * N [0] * N nodes
import sys
sys.setrecursionlimit(10**9)

N = int(input())
edge = [[] for _ in range(N)]

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

C = list(map(int, input().split()))
C.sort(reverse=True)
nodes = [0] * N

#print(nodes)
cidx = -1
ans = []
def dfs(v, pv, w):
    global cidx
    cidx += 1
    nodes[v] = C[cidx]
    ans.append(min(w, C[cidx]))
    for nv in edge[v]:
        if pv == nv: continue
        dfs(nv, v, C[cidx])

dfs(0, 0, 0)
print(sum(ans))
print(*nodes, sep=" ")
