# -*- coding: utf-8 -*-
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
edge=[[] for _ in range(N)]
for _ in range(N-1):
    a,b=map(int1,input().split())
    edge[a].append(b)
    edge[b].append(a)
C=list(map(int,input().split()))
C.sort()
print(sum(C)-C[-1])
que=deque([0])
ans=[-1]*N
while que:
    v=que.popleft()
    ans[v]=C.pop()
    for nv in edge[v]:
        if ans[nv]==-1:
            que.append(nv)
print(*ans) import sys sys from collections import deque sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 INF=10**18 INF 10**18 10 18 MOD=10**9+7 MOD 10**9+7 10**9 10 9 7 input=lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip YesNo=lambda b: bool([print('Yes')] if b else print('No')) YesNo lambda b: bool([print('Yes')] if b else print('No')) bool([print('Yes')] if b else print('No')) bool [print('Yes')] if b else print('No') b [print('Yes')] print('Yes') print 'Yes' print('No') print 'No' b YESNO=lambda b: bool([print('YES')] if b else print('NO')) YESNO lambda b: bool([print('YES')] if b else print('NO')) bool([print('YES')] if b else print('NO')) bool [print('YES')] if b else print('NO') b [print('YES')] print('YES') print 'YES' print('NO') print 'NO' b int1=lambda x:int(x)-1 int1 lambda x:int(x)-1 int(x)-1 int(x) int x 1 x 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) [] edge=[[] for _ in range(N)] edge [[] for _ in range(N)] for _ in range(N-1):
    a,b=map(int1,input().split())
    edge[a].append(b)
    edge[b].append(a) _ range(N-1) range N-1 N 1 a,b=map(int1,input().split()) a map(int1,input().split()) map int1 input().split() ().split () input split b edge[a].append(b) [a].append [a] edge a append b edge[b].append(a) [b].append [b] edge b append a 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() C.sort C sort print(sum(C)-C[-1]) print sum(C)-C[-1] sum(C) sum C C[-1] C -1 que=deque([0]) que deque([0]) deque [0] 0 ans=[-1]*N ans [-1]*N [-1] -1 N while que:
    v=que.popleft()
    ans[v]=C.pop()
    for nv in edge[v]:
        if ans[nv]==-1:
            que.append(nv) que v=que.popleft() v que.popleft() que.popleft que popleft ans[v]=C.pop() ans[v] ans v C.pop() C.pop C pop for nv in edge[v]:
        if ans[nv]==-1:
            que.append(nv) nv edge[v] edge v if ans[nv]==-1:
            que.append(nv) ans[nv]==-1 ans[nv] ans nv -1 que.append(nv) que.append que append nv print(*ans) print *ans ans int1=lambda x:int(x)-1 lambda x:int(x)-1 int1 b=map(int1,input().split()) map(int1,input().split()) b YESNO=lambda b: bool([print('YES')] if b else print('NO')) lambda b: bool([print('YES')] if b else print('NO')) YESNO a,b=map(int1,input().split()) map(int1,input().split()) a input=lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input C=list(map(int,input().split())) list(map(int,input().split())) C N=int(input()) int(input()) N MOD=10**9+7 10**9+7 MOD que=deque([0]) deque([0]) que ans=[-1]*N [-1]*N ans YesNo=lambda b: bool([print('Yes')] if b else print('No')) lambda b: bool([print('Yes')] if b else print('No')) YesNo v=que.popleft() que.popleft() v INF=10**18 10**18 INF edge=[[] for _ in range(N)] [[] for _ in range(N)] edge
# -*- coding: utf-8 -*-
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
edge=[[] for _ in range(N)]
for _ in range(N-1):
    a,b=map(int1,input().split())
    edge[a].append(b)
    edge[b].append(a)
C=list(map(int,input().split()))
C.sort()
print(sum(C)-C[-1])
que=deque([0])
ans=[-1]*N
while que:
    v=que.popleft()
    ans[v]=C.pop()
    for nv in edge[v]:
        if ans[nv]==-1:
            que.append(nv)
print(*ans)