import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def dfs(L, v, p, D):
    for w in L[v]:
        if w == p:
            continue
        dfs(L, w, v, D)
    D.append(v)


def main():
    N = int(input())
    L = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = read_index()
        L[a].add(b)
        L[b].add(a)
    
    C = read_list()
    C.sort()

    D = []
    dfs(L, 0, -1, D)
    E = [""] * N
    for i, d in enumerate(D):
        E[d] = str(C[i])
    
    print(sum(C[: N - 1]))
    print(" ".join(E))


if __name__ == "__main__":
    main() import sys sys from collections import deque import bisect bisect import copy copy import heapq heapq import itertools itertools import math math input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 def read_values(): return map(int, input().split()) read_values def read_index(): return map(lambda x: int(x) - 1, input().split()) read_index def read_list(): return list(read_values()) read_list read_list() for n in range(N) for n in range(N) n range(N) range N for n in range(N) read_list() read_list def read_lists(N): return [read_list() for n in range(N)] read_lists N N def dfs(L, v, p, D):
    for w in L[v]:
        if w == p:
            continue
        dfs(L, w, v, D)
    D.append(v) dfs for w in L[v]:
        if w == p:
            continue
        dfs(L, w, v, D)
     w L[v] L v if w == p:
            continue
         w == p w p continue dfs(L, w, v, D) dfs L w v D D.append(v) D.append D append v L L v v p p D D def main():
    N = int(input())
    L = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = read_index()
        L[a].add(b)
        L[b].add(a)
    
    C = read_list()
    C.sort()

    D = []
    dfs(L, 0, -1, D)
    E = [""] * N
    for i, d in enumerate(D):
        E[d] = str(C[i])
    
    print(sum(C[: N - 1]))
    print(" ".join(E)) main N = int(input()) N int(input()) int input() input set() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) set() set L = [set() for _ in range(N)] L [set() for _ in range(N)] for _ in range(N - 1):
        a, b = read_index()
        L[a].add(b)
        L[b].add(a)
    
     _ range(N - 1) range N - 1 N 1 a, b = read_index() a read_index() read_index b L[a].add(b) [a].add [a] L a add b L[b].add(a) [b].add [b] L b add a C = read_list() C read_list() read_list C.sort() C.sort C sort D = [] D [] dfs(L, 0, -1, D) dfs L 0 -1 D E = [""] * N E [""] * N [""] "" N for i, d in enumerate(D):
        E[d] = str(C[i])
    
     i d enumerate(D) enumerate D E[d] = str(C[i]) E[d] E d str(C[i]) str C[i] C i print(sum(C[: N - 1])) print sum(C[: N - 1]) sum C[: N - 1] C : N - 1 N - 1 N 1 print(" ".join(E)) print " ".join(E) " ".join " " join E if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def read_lists(N): return [read_list() for n in range(N)] def read_lists(N): return [read_list() for n in range(N)] read_lists def read_index(): return map(lambda x: int(x) - 1, input().split()) def read_index(): return map(lambda x: int(x) - 1, input().split()) read_index def read_list(): return list(read_values()) def read_list(): return list(read_values()) read_list mod = 10 ** 9 + 7 10 ** 9 + 7 mod def main():
    N = int(input())
    L = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = read_index()
        L[a].add(b)
        L[b].add(a)
    
    C = read_list()
    C.sort()

    D = []
    dfs(L, 0, -1, D)
    E = [""] * N
    for i, d in enumerate(D):
        E[d] = str(C[i])
    
    print(sum(C[: N - 1]))
    print(" ".join(E)) def main():
    N = int(input())
    L = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = read_index()
        L[a].add(b)
        L[b].add(a)
    
    C = read_list()
    C.sort()

    D = []
    dfs(L, 0, -1, D)
    E = [""] * N
    for i, d in enumerate(D):
        E[d] = str(C[i])
    
    print(sum(C[: N - 1]))
    print(" ".join(E)) main input = sys.stdin.readline sys.stdin.readline input def read_values(): return map(int, input().split()) def read_values(): return map(int, input().split()) read_values def dfs(L, v, p, D):
    for w in L[v]:
        if w == p:
            continue
        dfs(L, w, v, D)
    D.append(v) def dfs(L, v, p, D):
    for w in L[v]:
        if w == p:
            continue
        dfs(L, w, v, D)
    D.append(v) dfs
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def dfs(L, v, p, D):
    for w in L[v]:
        if w == p:
            continue
        dfs(L, w, v, D)
    D.append(v)


def main():
    N = int(input())
    L = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = read_index()
        L[a].add(b)
        L[b].add(a)
    
    C = read_list()
    C.sort()

    D = []
    dfs(L, 0, -1, D)
    E = [""] * N
    for i, d in enumerate(D):
        E[d] = str(C[i])
    
    print(sum(C[: N - 1]))
    print(" ".join(E))


if __name__ == "__main__":
    main()