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

q = [0]
checked = [False]*N
checked[0] = True
ans = 0
c = 0
score = [None for _ in range(N)]
score[0] = C[c]

while q:
    qq = []
    for p in q:
        for np in graph[p]:
            if not checked[np]:
                qq.append(np)
                checked[np] = True
                c += 1
                score[np] = C[c]
                ans += min(score[np], score[p])
    q = qq

print(ans)
for s in score:
    print(s, end=' ')
print() 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) [] graph = [[] for _ in range(N)] graph [[] for _ in range(N)] for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[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 graph[a-1].append(b-1) [a-1].append [a-1] graph a-1 a 1 append b-1 b 1 graph[b-1].append(a-1) [b-1].append [b-1] graph 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 q = [0] q [0] 0 checked = [False]*N checked [False]*N [False] False N checked[0] = True checked[0] checked 0 True ans = 0 ans 0 c = 0 c 0 None for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) None score = [None for _ in range(N)] score [None for _ in range(N)] score[0] = C[c] score[0] score 0 C[c] C c while q:
    qq = []
    for p in q:
        for np in graph[p]:
            if not checked[np]:
                qq.append(np)
                checked[np] = True
                c += 1
                score[np] = C[c]
                ans += min(score[np], score[p])
    q = qq q qq = [] qq [] for p in q:
        for np in graph[p]:
            if not checked[np]:
                qq.append(np)
                checked[np] = True
                c += 1
                score[np] = C[c]
                ans += min(score[np], score[p])
     p q for np in graph[p]:
            if not checked[np]:
                qq.append(np)
                checked[np] = True
                c += 1
                score[np] = C[c]
                ans += min(score[np], score[p])
     np graph[p] graph p if not checked[np]:
                qq.append(np)
                checked[np] = True
                c += 1
                score[np] = C[c]
                ans += min(score[np], score[p])
     not checked[np] checked[np] checked np qq.append(np) qq.append qq append np checked[np] = True checked[np] checked np True c += 1 c 1 score[np] = C[c] score[np] score np C[c] C c ans += min(score[np], score[p]) ans min(score[np], score[p]) min score[np] score np score[p] score p q = qq q qq print(ans) print ans for s in score:
    print(s, end=' ') s score print(s, end=' ') print s end=' ' end ' ' print() print c = 0 0 c C = list(map(int, input().split())) list(map(int, input().split())) C q = [0] [0] q score = [None for _ in range(N)] [None for _ in range(N)] score a, b = map(int, input().split()) map(int, input().split()) a graph = [[] for _ in range(N)] [[] for _ in range(N)] graph ans += min(score[np], score[p]) min(score[np], score[p]) ans qq = [] [] qq checked = [False]*N [False]*N checked ans = 0 0 ans q = qq qq q N = int(input()) int(input()) N b = map(int, input().split()) map(int, input().split()) b c += 1 1 c
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
C = list(map(int, input().split()))
C.sort(reverse=True)

q = [0]
checked = [False]*N
checked[0] = True
ans = 0
c = 0
score = [None for _ in range(N)]
score[0] = C[c]

while q:
    qq = []
    for p in q:
        for np in graph[p]:
            if not checked[np]:
                qq.append(np)
                checked[np] = True
                c += 1
                score[np] = C[c]
                ans += min(score[np], score[p])
    q = qq

print(ans)
for s in score:
    print(s, end=' ')
print()
