import sys
sys.setrecursionlimit(10**7)
def dfs(v,p):
    ans[v]=c.pop()
    for nv in G[v]:
        if nv==p:
            continue
        dfs(nv,v)

N=int(input())
G=[[] for i in range(N)]

for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
c=sorted(map(int,input().split()))
print(sum(c[:-1]))
ans=[-1]*N
dfs(0,-1)
print(*ans) import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def dfs(v,p):
    ans[v]=c.pop()
    for nv in G[v]:
        if nv==p:
            continue
        dfs(nv,v) dfs ans[v]=c.pop() ans[v] ans v c.pop() c.pop c pop for nv in G[v]:
        if nv==p:
            continue
        dfs(nv,v) nv G[v] G v if nv==p:
            continue
         nv==p nv p continue dfs(nv,v) dfs nv v v v p p N=int(input()) N int(input()) int input() input [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] G=[[] for i in range(N)] G [[] for i in range(N)] for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a) i range(N-1) range N-1 N 1 a,b=map(lambda x:int(x)-1,input().split()) a map(lambda x:int(x)-1,input().split()) map lambda x:int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split b G[a].append(b) [a].append [a] G a append b G[b].append(a) [b].append [b] G b append a c=sorted(map(int,input().split())) c sorted(map(int,input().split())) sorted map(int,input().split()) map int input().split() ().split () input split print(sum(c[:-1])) print sum(c[:-1]) sum c[:-1] c :-1 -1 ans=[-1]*N ans [-1]*N [-1] -1 N dfs(0,-1) dfs 0 -1 print(*ans) print *ans ans G=[[] for i in range(N)] [[] for i in range(N)] G N=int(input()) int(input()) N def dfs(v,p):
    ans[v]=c.pop()
    for nv in G[v]:
        if nv==p:
            continue
        dfs(nv,v) def dfs(v,p):
    ans[v]=c.pop()
    for nv in G[v]:
        if nv==p:
            continue
        dfs(nv,v) dfs a,b=map(lambda x:int(x)-1,input().split()) map(lambda x:int(x)-1,input().split()) a ans=[-1]*N [-1]*N ans b=map(lambda x:int(x)-1,input().split()) map(lambda x:int(x)-1,input().split()) b c=sorted(map(int,input().split())) sorted(map(int,input().split())) c
import sys
sys.setrecursionlimit(10**7)
def dfs(v,p):
    ans[v]=c.pop()
    for nv in G[v]:
        if nv==p:
            continue
        dfs(nv,v)

N=int(input())
G=[[] for i in range(N)]

for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
c=sorted(map(int,input().split()))
print(sum(c[:-1]))
ans=[-1]*N
dfs(0,-1)
print(*ans)