n = int(input())
adj_path = [[] for _ in range(n)]
paths = []
for _ in range(n-1):
    a,b = map(int,input().split())
    paths.append([a,b])
    adj_path[a-1].append(b-1)
    adj_path[b-1].append(a-1)
c_list = sorted(list(map(int,input().split())),reverse=True)
out = [0 for i in range(n)]
que = [[0,adj_path[0]]]
visited = []
cnt = 0
while(que):
    node_num,children = que.pop(0)
    visited.append(node_num)
    out[node_num] = c_list[cnt]
    cnt += 1
    for child in children:
        if child not in visited:
            que.append([child,adj_path[child]])
score = 0
for path in paths:
    a,b = path
    score += min(out[a-1],out[b-1])
print(score)
print(" ".join(str(x) for x in out)) 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) [] adj_path = [[] for _ in range(n)] adj_path [[] for _ in range(n)] paths = [] paths [] for _ in range(n-1):
    a,b = map(int,input().split())
    paths.append([a,b])
    adj_path[a-1].append(b-1)
    adj_path[b-1].append(a-1) _ range(n-1) range n-1 n 1 a,b = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b paths.append([a,b]) paths.append paths append [a,b] a b adj_path[a-1].append(b-1) [a-1].append [a-1] adj_path a-1 a 1 append b-1 b 1 adj_path[b-1].append(a-1) [b-1].append [b-1] adj_path b-1 b 1 append a-1 a 1 c_list = sorted(list(map(int,input().split())),reverse=True) c_list sorted(list(map(int,input().split())),reverse=True) sorted list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split reverse=True reverse True 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 out = [0 for i in range(n)] out [0 for i in range(n)] que = [[0,adj_path[0]]] que [[0,adj_path[0]]] [0,adj_path[0]] 0 adj_path[0] adj_path 0 visited = [] visited [] cnt = 0 cnt 0 while(que):
    node_num,children = que.pop(0)
    visited.append(node_num)
    out[node_num] = c_list[cnt]
    cnt += 1
    for child in children:
        if child not in visited:
            que.append([child,adj_path[child]]) que node_num,children = que.pop(0) node_num que.pop(0) que.pop que pop 0 children visited.append(node_num) visited.append visited append node_num out[node_num] = c_list[cnt] out[node_num] out node_num c_list[cnt] c_list cnt cnt += 1 cnt 1 for child in children:
        if child not in visited:
            que.append([child,adj_path[child]]) child children if child not in visited:
            que.append([child,adj_path[child]]) child not in visited child visited que.append([child,adj_path[child]]) que.append que append [child,adj_path[child]] child adj_path[child] adj_path child score = 0 score 0 for path in paths:
    a,b = path
    score += min(out[a-1],out[b-1]) path paths a,b = path a path b score += min(out[a-1],out[b-1]) score min(out[a-1],out[b-1]) min out[a-1] out a-1 a 1 out[b-1] out b-1 b 1 print(score) print score print(" ".join(str(x) for x in out)) print " ".join(str(x) for x in out) " ".join " " join str(x) str x c_list = sorted(list(map(int,input().split())),reverse=True) sorted(list(map(int,input().split())),reverse=True) c_list score = 0 0 score children = que.pop(0) que.pop(0) children visited = [] [] visited b = path path b n = int(input()) int(input()) n b = map(int,input().split()) map(int,input().split()) b adj_path = [[] for _ in range(n)] [[] for _ in range(n)] adj_path out = [0 for i in range(n)] [0 for i in range(n)] out score += min(out[a-1],out[b-1]) min(out[a-1],out[b-1]) score a,b = map(int,input().split()) map(int,input().split()) a cnt += 1 1 cnt que = [[0,adj_path[0]]] [[0,adj_path[0]]] que node_num,children = que.pop(0) que.pop(0) node_num paths = [] [] paths cnt = 0 0 cnt a,b = path path a
n = int(input())
adj_path = [[] for _ in range(n)]
paths = []
for _ in range(n-1):
    a,b = map(int,input().split())
    paths.append([a,b])
    adj_path[a-1].append(b-1)
    adj_path[b-1].append(a-1)
c_list = sorted(list(map(int,input().split())),reverse=True)
out = [0 for i in range(n)]
que = [[0,adj_path[0]]]
visited = []
cnt = 0
while(que):
    node_num,children = que.pop(0)
    visited.append(node_num)
    out[node_num] = c_list[cnt]
    cnt += 1
    for child in children:
        if child not in visited:
            que.append([child,adj_path[child]])
score = 0
for path in paths:
    a,b = path
    score += min(out[a-1],out[b-1])
print(score)
print(" ".join(str(x) for x in out))
