N = int(input())

edges = [[] for _ in range(N)]
for _ in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append(to)
    edges[to].append(fr)
C = list(map(int, input().split()))
A = sum(C) - max(C)
C.sort()

ans = [None] * N
ans[0] = C.pop()
st = [0]
while st:
    now = st.pop()
    for to in edges[now]:
        if ans[to] == None:
            ans[to] = C.pop()
            st.append(to)

print(A)
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) [] edges = [[] for _ in range(N)] edges [[] for _ in range(N)] for _ in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append(to)
    edges[to].append(fr) _ range(N - 1) range N - 1 N 1 fr, to = map(lambda a: int(a) - 1, input().split()) fr map(lambda a: int(a) - 1, input().split()) map lambda a: int(a) - 1 int(a) - 1 int(a) int a 1 a input().split() ().split () input split to edges[fr].append(to) [fr].append [fr] edges fr append to edges[to].append(fr) [to].append [to] edges to append fr C = list(map(int, input().split())) C list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split A = sum(C) - max(C) A sum(C) - max(C) sum(C) sum C max(C) max C C.sort() C.sort C sort ans = [None] * N ans [None] * N [None] None N ans[0] = C.pop() ans[0] ans 0 C.pop() C.pop C pop st = [0] st [0] 0 while st:
    now = st.pop()
    for to in edges[now]:
        if ans[to] == None:
            ans[to] = C.pop()
            st.append(to) st now = st.pop() now st.pop() st.pop st pop for to in edges[now]:
        if ans[to] == None:
            ans[to] = C.pop()
            st.append(to) to edges[now] edges now if ans[to] == None:
            ans[to] = C.pop()
            st.append(to) ans[to] == None ans[to] ans to None ans[to] = C.pop() ans[to] ans to C.pop() C.pop C pop st.append(to) st.append st append to print(A) print A print(*ans) print *ans ans A = sum(C) - max(C) sum(C) - max(C) A to = map(lambda a: int(a) - 1, input().split()) map(lambda a: int(a) - 1, input().split()) to ans = [None] * N [None] * N ans st = [0] [0] st C = list(map(int, input().split())) list(map(int, input().split())) C N = int(input()) int(input()) N fr, to = map(lambda a: int(a) - 1, input().split()) map(lambda a: int(a) - 1, input().split()) fr edges = [[] for _ in range(N)] [[] for _ in range(N)] edges now = st.pop() st.pop() now
N = int(input())

edges = [[] for _ in range(N)]
for _ in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append(to)
    edges[to].append(fr)
C = list(map(int, input().split()))
A = sum(C) - max(C)
C.sort()

ans = [None] * N
ans[0] = C.pop()
st = [0]
while st:
    now = st.pop()
    for to in edges[now]:
        if ans[to] == None:
            ans[to] = C.pop()
            st.append(to)

print(A)
print(*ans)
