import sys

sys.setrecursionlimit(10 ** 9 + 7)

N = int(input())
visited = [False] * N
edges = [[] for _ in range(N)]
AB = []
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB.append((a, b))
    edges[a].append(b)
    edges[b].append(a)
C = list(map(int, input().split()))
C.sort(reverse=True)
scores = [-1] * N
i = 0

def dfs(v):
    if visited[v]:
        return

    visited[v] = True
    global i
    scores[v] = C[i]
    i += 1
    for e in edges[v]:
        if visited[e]:
            continue

        dfs(e)

dfs(0)

total = 0
for a, b in AB:
    total += min(scores[a], scores[b])
print(total)
print(*scores) import sys sys sys.setrecursionlimit(10 ** 9 + 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 + 7 10 ** 9 10 9 7 N = int(input()) N int(input()) int input() input visited = [False] * N visited [False] * N [False] False N [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] edges = [[] for _ in range(N)] edges [[] for _ in range(N)] AB = [] AB [] for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB.append((a, b))
    edges[a].append(b)
    edges[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 AB.append((a, b)) AB.append AB append (a, b) a b edges[a].append(b) [a].append [a] edges a append b edges[b].append(a) [b].append [b] edges 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 scores = [-1] * N scores [-1] * N [-1] -1 N i = 0 i 0 def dfs(v):
    if visited[v]:
        return

    visited[v] = True
    global i
    scores[v] = C[i]
    i += 1
    for e in edges[v]:
        if visited[e]:
            continue

        dfs(e) dfs if visited[v]:
        return

     visited[v] visited v return visited[v] = True visited[v] visited v True global i scores[v] = C[i] scores[v] scores v C[i] C i i += 1 i 1 for e in edges[v]:
        if visited[e]:
            continue

        dfs(e) e edges[v] edges v if visited[e]:
            continue

         visited[e] visited e continue dfs(e) dfs e v v dfs(0) dfs 0 total = 0 total 0 for a, b in AB:
    total += min(scores[a], scores[b]) a b AB total += min(scores[a], scores[b]) total min(scores[a], scores[b]) min scores[a] scores a scores[b] scores b print(total) print total print(*scores) print *scores scores i = 0 0 i def dfs(v):
    if visited[v]:
        return

    visited[v] = True
    global i
    scores[v] = C[i]
    i += 1
    for e in edges[v]:
        if visited[e]:
            continue

        dfs(e) def dfs(v):
    if visited[v]:
        return

    visited[v] = True
    global i
    scores[v] = C[i]
    i += 1
    for e in edges[v]:
        if visited[e]:
            continue

        dfs(e) dfs b = map(int, input().split()) map(int, input().split()) b total = 0 0 total N = int(input()) int(input()) N total += min(scores[a], scores[b]) min(scores[a], scores[b]) total C = list(map(int, input().split())) list(map(int, input().split())) C a, b = map(int, input().split()) map(int, input().split()) a AB = [] [] AB a -= 1 1 a visited = [False] * N [False] * N visited b -= 1 1 b scores = [-1] * N [-1] * N scores edges = [[] for _ in range(N)] [[] for _ in range(N)] edges
import sys

sys.setrecursionlimit(10 ** 9 + 7)

N = int(input())
visited = [False] * N
edges = [[] for _ in range(N)]
AB = []
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB.append((a, b))
    edges[a].append(b)
    edges[b].append(a)
C = list(map(int, input().split()))
C.sort(reverse=True)
scores = [-1] * N
i = 0

def dfs(v):
    if visited[v]:
        return

    visited[v] = True
    global i
    scores[v] = C[i]
    i += 1
    for e in edges[v]:
        if visited[e]:
            continue

        dfs(e)

dfs(0)

total = 0
for a, b in AB:
    total += min(scores[a], scores[b])
print(total)
print(*scores)