import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
edges = [[]for _ in range(n)]
for _ in range(n-1):
    a, b = map(lambda x: int(x)-1, input().split())
    edges[a].append(b)
    edges[b].append(a)


cost = sorted(map(int, input().split()))
m = 0
ans = [None]*n


def dfs(v, parent):
    ans[v] = cost.pop()
    if parent != -1:
        global m
        m += min(ans[v], ans[parent])
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v)


dfs(0, -1)
print(m)
print(*ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 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) [] edges = [[]for _ in range(n)] edges [[]for _ in range(n)] for _ in range(n-1):
    a, b = map(lambda x: int(x)-1, input().split())
    edges[a].append(b)
    edges[b].append(a) _ range(n-1) range n-1 n 1 a, b = map(lambda x: int(x)-1, input().split()) a map(lambda x: int(x)-1, input().split()) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split b edges[a].append(b) [a].append [a] edges a append b edges[b].append(a) [b].append [b] edges b append a cost = sorted(map(int, input().split())) cost sorted(map(int, input().split())) sorted map(int, input().split()) map int input().split() ().split () input split m = 0 m 0 ans = [None]*n ans [None]*n [None] None n def dfs(v, parent):
    ans[v] = cost.pop()
    if parent != -1:
        global m
        m += min(ans[v], ans[parent])
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v) dfs ans[v] = cost.pop() ans[v] ans v cost.pop() cost.pop cost pop if parent != -1:
        global m
        m += min(ans[v], ans[parent])
     parent != -1 parent -1 global m m += min(ans[v], ans[parent]) m min(ans[v], ans[parent]) min ans[v] ans v ans[parent] ans parent for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v) v2 edges[v] edges v if v2 == parent:
            continue
         v2 == parent v2 parent continue dfs(v2, v) dfs v2 v v v parent parent dfs(0, -1) dfs 0 -1 print(m) print m print(*ans) print *ans ans edges = [[]for _ in range(n)] [[]for _ in range(n)] edges input = sys.stdin.readline sys.stdin.readline input m = 0 0 m n = int(input()) int(input()) n b = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) b cost = sorted(map(int, input().split())) sorted(map(int, input().split())) cost ans = [None]*n [None]*n ans a, b = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) a def dfs(v, parent):
    ans[v] = cost.pop()
    if parent != -1:
        global m
        m += min(ans[v], ans[parent])
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v) def dfs(v, parent):
    ans[v] = cost.pop()
    if parent != -1:
        global m
        m += min(ans[v], ans[parent])
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v) dfs
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
edges = [[]for _ in range(n)]
for _ in range(n-1):
    a, b = map(lambda x: int(x)-1, input().split())
    edges[a].append(b)
    edges[b].append(a)


cost = sorted(map(int, input().split()))
m = 0
ans = [None]*n


def dfs(v, parent):
    ans[v] = cost.pop()
    if parent != -1:
        global m
        m += min(ans[v], ans[parent])
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v)


dfs(0, -1)
print(m)
print(*ans)
