import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
Graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = MI()
    Graph[a].append(b)
    Graph[b].append(a)
C = LI()
C.sort(reverse=True)
print(sum(C[1:]))

ANS = [-1]*(N+1)
index = 0


def dfs(x,i):
    global index
    ANS[x] = C[i]
    for y in Graph[x]:
        if ANS[y] == -1:
            index += 1
            dfs(y,index)


dfs(1,0)
print(*ANS[1:]) import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def I(): return int(sys.stdin.readline().rstrip()) I def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI N = I() N I() I [] for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [] Graph = [[] for _ in range(N+1)] Graph [[] for _ in range(N+1)] for _ in range(N-1):
    a,b = MI()
    Graph[a].append(b)
    Graph[b].append(a) _ range(N-1) range N-1 N 1 a,b = MI() a MI() MI b Graph[a].append(b) [a].append [a] Graph a append b Graph[b].append(a) [b].append [b] Graph b append a C = LI() C LI() LI C.sort(reverse=True) C.sort C sort reverse=True reverse True print(sum(C[1:])) print sum(C[1:]) sum C[1:] C 1: 1 ANS = [-1]*(N+1) ANS [-1]*(N+1) [-1] -1 N+1 N 1 index = 0 index 0 def dfs(x,i):
    global index
    ANS[x] = C[i]
    for y in Graph[x]:
        if ANS[y] == -1:
            index += 1
            dfs(y,index) dfs global index ANS[x] = C[i] ANS[x] ANS x C[i] C i for y in Graph[x]:
        if ANS[y] == -1:
            index += 1
            dfs(y,index) y Graph[x] Graph x if ANS[y] == -1:
            index += 1
            dfs(y,index) ANS[y] == -1 ANS[y] ANS y -1 index += 1 index 1 dfs(y,index) dfs y index x x i i dfs(1,0) dfs 1 0 print(*ANS[1:]) print *ANS[1:] ANS[1:] ANS 1: 1 ANS = [-1]*(N+1) [-1]*(N+1) ANS def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI def dfs(x,i):
    global index
    ANS[x] = C[i]
    for y in Graph[x]:
        if ANS[y] == -1:
            index += 1
            dfs(y,index) def dfs(x,i):
    global index
    ANS[x] = C[i]
    for y in Graph[x]:
        if ANS[y] == -1:
            index += 1
            dfs(y,index) dfs N = I() I() N b = MI() MI() b def MI(): return map(int,sys.stdin.readline().rstrip().split()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI index = 0 0 index Graph = [[] for _ in range(N+1)] [[] for _ in range(N+1)] Graph a,b = MI() MI() a C = LI() LI() C
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
Graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = MI()
    Graph[a].append(b)
    Graph[b].append(a)
C = LI()
C.sort(reverse=True)
print(sum(C[1:]))

ANS = [-1]*(N+1)
index = 0


def dfs(x,i):
    global index
    ANS[x] = C[i]
    for y in Graph[x]:
        if ANS[y] == -1:
            index += 1
            dfs(y,index)


dfs(1,0)
print(*ANS[1:])
