*D, = open(0)
n = int(D[0])

edge = [[] for _ in range(n+1)]
v_val = [0 for _ in range(n+1)]

dist = {}

for i in range(1, n):
    a, b = map(int, D[i].split())
    edge[a].append(b)
    edge[b].append(a)
c = list(map(int, D[n].split()))
c = sorted(c, reverse=True)

start = None
for i in range(1,len(edge)):
    if len(edge[i])==1:
        start = i
        break

        
import sys
sys.setrecursionlimit(10**7)


def visit(edge, start, visited, order):
    visited[start] = True
    order.append(start)
    
    for node in edge[start]:
        if not visited[node]:
            visit(edge, node, visited, order)
    
    return 

visited = [False for _ in range(len(edge))]
order = []
visit(edge, start, visited, order)

# calculate cost
v_val = [0 for _ in range(len(c)+1)]
for i, it in enumerate(order):
    v_val[it] = c[i]
    
print(sum(c[1:]))
print(' '.join(map(str, v_val[1:]))) *D, = open(0) *D D open(0) open 0 n = int(D[0]) n int(D[0]) int D[0] D 0 [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] edge = [[] for _ in range(n+1)] edge [[] for _ in range(n+1)] 0 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) 0 v_val = [0 for _ in range(n+1)] v_val [0 for _ in range(n+1)] dist = {} dist {} for i in range(1, n):
    a, b = map(int, D[i].split())
    edge[a].append(b)
    edge[b].append(a) i range(1, n) range 1 n a, b = map(int, D[i].split()) a map(int, D[i].split()) map int D[i].split() [i].split [i] D i 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, D[n].split())) c list(map(int, D[n].split())) list map(int, D[n].split()) map int D[n].split() [n].split [n] D n split c = sorted(c, reverse=True) c sorted(c, reverse=True) sorted c reverse=True reverse True start = None start None for i in range(1,len(edge)):
    if len(edge[i])==1:
        start = i
        break

         i range(1,len(edge)) range 1 len(edge) len edge if len(edge[i])==1:
        start = i
        break

         len(edge[i])==1 len(edge[i]) len edge[i] edge i 1 start = i start i break import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def visit(edge, start, visited, order):
    visited[start] = True
    order.append(start)
    
    for node in edge[start]:
        if not visited[node]:
            visit(edge, node, visited, order)
    
    return  visit visited[start] = True visited[start] visited start True order.append(start) order.append order append start for node in edge[start]:
        if not visited[node]:
            visit(edge, node, visited, order)
    
     node edge[start] edge start if not visited[node]:
            visit(edge, node, visited, order)
    
     not visited[node] visited[node] visited node visit(edge, node, visited, order) visit edge node visited order return edge edge start start visited visited order order False for _ in range(len(edge)) for _ in range(len(edge)) _ range(len(edge)) range len(edge) len edge for _ in range(len(edge)) False visited = [False for _ in range(len(edge))] visited [False for _ in range(len(edge))] order = [] order [] visit(edge, start, visited, order) visit edge start visited order 0 for _ in range(len(c)+1) for _ in range(len(c)+1) _ range(len(c)+1) range len(c)+1 len(c) len c 1 for _ in range(len(c)+1) 0 v_val = [0 for _ in range(len(c)+1)] v_val [0 for _ in range(len(c)+1)] for i, it in enumerate(order):
    v_val[it] = c[i]
     i it enumerate(order) enumerate order v_val[it] = c[i] v_val[it] v_val it c[i] c i print(sum(c[1:])) print sum(c[1:]) sum c[1:] c 1: 1 print(' '.join(map(str, v_val[1:]))) print ' '.join(map(str, v_val[1:])) ' '.join ' ' join map(str, v_val[1:]) map str v_val[1:] v_val 1: 1 visited = [False for _ in range(len(edge))] [False for _ in range(len(edge))] visited order = [] [] order v_val = [0 for _ in range(n+1)] [0 for _ in range(n+1)] v_val a, b = map(int, D[i].split()) map(int, D[i].split()) a def visit(edge, start, visited, order):
    visited[start] = True
    order.append(start)
    
    for node in edge[start]:
        if not visited[node]:
            visit(edge, node, visited, order)
    
    return  def visit(edge, start, visited, order):
    visited[start] = True
    order.append(start)
    
    for node in edge[start]:
        if not visited[node]:
            visit(edge, node, visited, order)
    
    return  visit dist = {} {} dist start = None None start n = int(D[0]) int(D[0]) n v_val = [0 for _ in range(len(c)+1)] [0 for _ in range(len(c)+1)] v_val edge = [[] for _ in range(n+1)] [[] for _ in range(n+1)] edge b = map(int, D[i].split()) map(int, D[i].split()) b start = i i start c = list(map(int, D[n].split())) list(map(int, D[n].split())) c c = sorted(c, reverse=True) sorted(c, reverse=True) c
*D, = open(0)
n = int(D[0])

edge = [[] for _ in range(n+1)]
v_val = [0 for _ in range(n+1)]

dist = {}

for i in range(1, n):
    a, b = map(int, D[i].split())
    edge[a].append(b)
    edge[b].append(a)
c = list(map(int, D[n].split()))
c = sorted(c, reverse=True)

start = None
for i in range(1,len(edge)):
    if len(edge[i])==1:
        start = i
        break

        
import sys
sys.setrecursionlimit(10**7)


def visit(edge, start, visited, order):
    visited[start] = True
    order.append(start)
    
    for node in edge[start]:
        if not visited[node]:
            visit(edge, node, visited, order)
    
    return 

visited = [False for _ in range(len(edge))]
order = []
visit(edge, start, visited, order)

# calculate cost
v_val = [0 for _ in range(len(c)+1)]
for i, it in enumerate(order):
    v_val[it] = c[i]
    
print(sum(c[1:]))
print(' '.join(map(str, v_val[1:])))