n = int(input())
link = [[] for _ in range(n)]
for i in range(n-1):
    a,b = list(map(int,input().split()))
    link[a-1].append(b-1)
    link[b-1].append(a-1)
c=list(map(int, input().split()))
c.sort(reverse=True)
print(sum(c)-c[0])

from collections import deque
Q = deque()
Q.append(0)
visited=[-1]*n
visited[0]=0

ind=1
while Q:
    now = Q.popleft()
    for nxt in link[now]:
        if visited[nxt]!=-1:
            continue
        visited[nxt]=ind
        ind+=1
        Q.append(nxt)
for i in visited:
    print(c[i],end=" ") 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) [] link = [[] for _ in range(n)] link [[] for _ in range(n)] for i in range(n-1):
    a,b = list(map(int,input().split()))
    link[a-1].append(b-1)
    link[b-1].append(a-1) i range(n-1) range n-1 n 1 a,b = list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split b link[a-1].append(b-1) [a-1].append [a-1] link a-1 a 1 append b-1 b 1 link[b-1].append(a-1) [b-1].append [b-1] link 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 print(sum(c)-c[0]) print sum(c)-c[0] sum(c) sum c c[0] c 0 from collections import deque Q = deque() Q deque() deque Q.append(0) Q.append Q append 0 visited=[-1]*n visited [-1]*n [-1] -1 n visited[0]=0 visited[0] visited 0 0 ind=1 ind 1 while Q:
    now = Q.popleft()
    for nxt in link[now]:
        if visited[nxt]!=-1:
            continue
        visited[nxt]=ind
        ind+=1
        Q.append(nxt) Q now = Q.popleft() now Q.popleft() Q.popleft Q popleft for nxt in link[now]:
        if visited[nxt]!=-1:
            continue
        visited[nxt]=ind
        ind+=1
        Q.append(nxt) nxt link[now] link now if visited[nxt]!=-1:
            continue
         visited[nxt]!=-1 visited[nxt] visited nxt -1 continue visited[nxt]=ind visited[nxt] visited nxt ind ind+=1 ind 1 Q.append(nxt) Q.append Q append nxt for i in visited:
    print(c[i],end=" ") i visited print(c[i],end=" ") print c[i] c i end=" " end " " c=list(map(int, input().split())) list(map(int, input().split())) c Q = deque() deque() Q now = Q.popleft() Q.popleft() now ind+=1 1 ind a,b = list(map(int,input().split())) list(map(int,input().split())) a visited=[-1]*n [-1]*n visited link = [[] for _ in range(n)] [[] for _ in range(n)] link ind=1 1 ind n = int(input()) int(input()) n b = list(map(int,input().split())) list(map(int,input().split())) b
n = int(input())
link = [[] for _ in range(n)]
for i in range(n-1):
    a,b = list(map(int,input().split()))
    link[a-1].append(b-1)
    link[b-1].append(a-1)
c=list(map(int, input().split()))
c.sort(reverse=True)
print(sum(c)-c[0])

from collections import deque
Q = deque()
Q.append(0)
visited=[-1]*n
visited[0]=0

ind=1
while Q:
    now = Q.popleft()
    for nxt in link[now]:
        if visited[nxt]!=-1:
            continue
        visited[nxt]=ind
        ind+=1
        Q.append(nxt)
for i in visited:
    print(c[i],end=" ")