import sys
sys.setrecursionlimit(4100000)

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

D = [0] * N

def dfs(x, parent, index):
    D[x] = C[index]
    index += 1
    for u in edges[x]:
        if u != parent:
            index = dfs(u, x, index)
    return index

dfs(0, -1, 0)

print(sum(C[1:]))
print(*D) import sys sys sys.setrecursionlimit(4100000) sys.setrecursionlimit sys setrecursionlimit 4100000 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(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1) _ 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 edges[a-1].append(b-1) [a-1].append [a-1] edges a-1 a 1 append b-1 b 1 edges[b-1].append(a-1) [b-1].append [b-1] edges b-1 b 1 append a-1 a 1 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 D = [0] * N D [0] * N [0] 0 N def dfs(x, parent, index):
    D[x] = C[index]
    index += 1
    for u in edges[x]:
        if u != parent:
            index = dfs(u, x, index)
    return index dfs D[x] = C[index] D[x] D x C[index] C index index += 1 index 1 for u in edges[x]:
        if u != parent:
            index = dfs(u, x, index)
     u edges[x] edges x if u != parent:
            index = dfs(u, x, index)
     u != parent u parent index = dfs(u, x, index) index dfs(u, x, index) dfs u x index return index index x x parent parent index index dfs(0, -1, 0) dfs 0 -1 0 print(sum(C[1:])) print sum(C[1:]) sum C[1:] C 1: 1 print(*D) print *D D b = map(int,input().split()) map(int,input().split()) b def dfs(x, parent, index):
    D[x] = C[index]
    index += 1
    for u in edges[x]:
        if u != parent:
            index = dfs(u, x, index)
    return index def dfs(x, parent, index):
    D[x] = C[index]
    index += 1
    for u in edges[x]:
        if u != parent:
            index = dfs(u, x, index)
    return index dfs C = list(map(int,input().split())) list(map(int,input().split())) C N = int(input()) int(input()) N edges = [[] for _ in range(N)] [[] for _ in range(N)] edges a, b = map(int,input().split()) map(int,input().split()) a D = [0] * N [0] * N D
import sys
sys.setrecursionlimit(4100000)

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

D = [0] * N

def dfs(x, parent, index):
    D[x] = C[index]
    index += 1
    for u in edges[x]:
        if u != parent:
            index = dfs(u, x, index)
    return index

dfs(0, -1, 0)

print(sum(C[1:]))
print(*D)