n = int(input())
ab = [list(map(int, input().split())) for _ in range(n-1)]
cl = list(map(int, input().split()))
cl.sort(reverse=True)

e = [set() for _ in range(n)]
for a,b in ab:
    a -= 1
    b -= 1
    e[a].add(b)
    e[b].add(a)

used = [False]*n
q = [0]

res = [0]*n
i = 0
while len(q)>0:
    u = q.pop()
    res[u] = cl[i]
    used[u] = True
    i += 1
    for v in e[u]:
        if not used[v]:
            q.append(v)

r = 0
for a,b in ab:
    r += min(res[a-1], res[b-1])
print(r)
print(*res) n = int(input()) n int(input()) int input() input list(map(int, input().split())) for _ in range(n-1) for _ in range(n-1) _ range(n-1) range n-1 n 1 for _ in range(n-1) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ab = [list(map(int, input().split())) for _ in range(n-1)] ab [list(map(int, input().split())) for _ in range(n-1)] cl = list(map(int, input().split())) cl list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cl.sort(reverse=True) cl.sort cl sort reverse=True reverse True set() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) set() set e = [set() for _ in range(n)] e [set() for _ in range(n)] for a,b in ab:
    a -= 1
    b -= 1
    e[a].add(b)
    e[b].add(a) a b ab a -= 1 a 1 b -= 1 b 1 e[a].add(b) [a].add [a] e a add b e[b].add(a) [b].add [b] e b add a used = [False]*n used [False]*n [False] False n q = [0] q [0] 0 res = [0]*n res [0]*n [0] 0 n i = 0 i 0 while len(q)>0:
    u = q.pop()
    res[u] = cl[i]
    used[u] = True
    i += 1
    for v in e[u]:
        if not used[v]:
            q.append(v) len(q)>0 len(q) len q 0 u = q.pop() u q.pop() q.pop q pop res[u] = cl[i] res[u] res u cl[i] cl i used[u] = True used[u] used u True i += 1 i 1 for v in e[u]:
        if not used[v]:
            q.append(v) v e[u] e u if not used[v]:
            q.append(v) not used[v] used[v] used v q.append(v) q.append q append v r = 0 r 0 for a,b in ab:
    r += min(res[a-1], res[b-1]) a b ab r += min(res[a-1], res[b-1]) r min(res[a-1], res[b-1]) min res[a-1] res a-1 a 1 res[b-1] res b-1 b 1 print(r) print r print(*res) print *res res e = [set() for _ in range(n)] [set() for _ in range(n)] e r += min(res[a-1], res[b-1]) min(res[a-1], res[b-1]) r u = q.pop() q.pop() u b -= 1 1 b used = [False]*n [False]*n used a -= 1 1 a q = [0] [0] q i = 0 0 i r = 0 0 r ab = [list(map(int, input().split())) for _ in range(n-1)] [list(map(int, input().split())) for _ in range(n-1)] ab n = int(input()) int(input()) n res = [0]*n [0]*n res cl = list(map(int, input().split())) list(map(int, input().split())) cl i += 1 1 i
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n-1)]
cl = list(map(int, input().split()))
cl.sort(reverse=True)

e = [set() for _ in range(n)]
for a,b in ab:
    a -= 1
    b -= 1
    e[a].add(b)
    e[b].add(a)

used = [False]*n
q = [0]

res = [0]*n
i = 0
while len(q)>0:
    u = q.pop()
    res[u] = cl[i]
    used[u] = True
    i += 1
    for v in e[u]:
        if not used[v]:
            q.append(v)

r = 0
for a,b in ab:
    r += min(res[a-1], res[b-1])
print(r)
print(*res)