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

C = list(map(int, input().split()))
C.sort(reverse=True)

order = []
par = [-1]*n
s = []
visit = [-1]*n
s.append(0)
visit[0] = 0
while s:
    v = s.pop()
    order.append(v)
    for u in g[v]:
        if u == par[v]:
            continue
        par[u] = v
        s.append(u)

order.reverse()
ans = [0]*n
m = 0
for v in order:
    ans[v] = C.pop()
    if par[v] != -1:
        m += ans[v]
print(m)
print(*ans) 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) [] g = [[] for _ in range(n)] g [[] for _ in range(n)] for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[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 g[a].append(b) [a].append [a] g a append b g[b].append(a) [b].append [b] g 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 order = [] order [] par = [-1]*n par [-1]*n [-1] -1 n s = [] s [] visit = [-1]*n visit [-1]*n [-1] -1 n s.append(0) s.append s append 0 visit[0] = 0 visit[0] visit 0 0 while s:
    v = s.pop()
    order.append(v)
    for u in g[v]:
        if u == par[v]:
            continue
        par[u] = v
        s.append(u) s v = s.pop() v s.pop() s.pop s pop order.append(v) order.append order append v for u in g[v]:
        if u == par[v]:
            continue
        par[u] = v
        s.append(u) u g[v] g v if u == par[v]:
            continue
         u == par[v] u par[v] par v continue par[u] = v par[u] par u v s.append(u) s.append s append u order.reverse() order.reverse order reverse ans = [0]*n ans [0]*n [0] 0 n m = 0 m 0 for v in order:
    ans[v] = C.pop()
    if par[v] != -1:
        m += ans[v] v order ans[v] = C.pop() ans[v] ans v C.pop() C.pop C pop if par[v] != -1:
        m += ans[v] par[v] != -1 par[v] par v -1 m += ans[v] m ans[v] ans v print(m) print m print(*ans) print *ans ans a, b = map(int, input().split()) map(int, input().split()) a b = a-1, b-1 b-1 b a, b = a-1, b-1 a-1 a ans = [0]*n [0]*n ans par = [-1]*n [-1]*n par n = int(input()) int(input()) n s = [] [] s visit = [-1]*n [-1]*n visit g = [[] for _ in range(n)] [[] for _ in range(n)] g v = s.pop() s.pop() v m += ans[v] ans[v] m order = [] [] order b = map(int, input().split()) map(int, input().split()) b m = 0 0 m C = list(map(int, input().split())) list(map(int, input().split())) C
n = int(input())
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)

C = list(map(int, input().split()))
C.sort(reverse=True)

order = []
par = [-1]*n
s = []
visit = [-1]*n
s.append(0)
visit[0] = 0
while s:
    v = s.pop()
    order.append(v)
    for u in g[v]:
        if u == par[v]:
            continue
        par[u] = v
        s.append(u)

order.reverse()
ans = [0]*n
m = 0
for v in order:
    ans[v] = C.pop()
    if par[v] != -1:
        m += ans[v]
print(m)
print(*ans)