def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    def bfs(n, e, fordfs, C):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        i = 0
        W[e] = C[i]
        i += 1
        que = deque()
        que.append(e)
        while que and i<n:
            now = que.popleft()
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = C[i]
                    i += 1
                    que.append(ne)
        return W
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        A, B = LI()
        V[A-1].append(B-1)
        V[B-1].append(A-1)
    C = LI(); C.sort(reverse=True)
    e = 0
    ans = bfs(N,e,V,C)
    print(sum(ans)-C[0])
    print(" ".join(map(str,ans)))
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

""" def examA():
    N = I()
    ans = 0
    print(ans)
    return examA N = I() N I() I ans = 0 ans 0 print(ans) print ans return def examB():
    ans = 0
    print(ans)
    return examB ans = 0 ans 0 print(ans) print ans return def examC():
    ans = 0
    print(ans)
    return examC ans = 0 ans 0 print(ans) print ans return def examD():
    def bfs(n, e, fordfs, C):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        i = 0
        W[e] = C[i]
        i += 1
        que = deque()
        que.append(e)
        while que and i<n:
            now = que.popleft()
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = C[i]
                    i += 1
                    que.append(ne)
        return W
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        A, B = LI()
        V[A-1].append(B-1)
        V[B-1].append(A-1)
    C = LI(); C.sort(reverse=True)
    e = 0
    ans = bfs(N,e,V,C)
    print(sum(ans)-C[0])
    print(" ".join(map(str,ans)))
    return examD def bfs(n, e, fordfs, C):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        i = 0
        W[e] = C[i]
        i += 1
        que = deque()
        que.append(e)
        while que and i<n:
            now = que.popleft()
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = C[i]
                    i += 1
                    que.append(ne)
        return W
     bfs W = [-1] * n W [-1] * n [-1] -1 n i = 0 i 0 W[e] = C[i] W[e] W e C[i] C i i += 1 i 1 que = deque() que deque() deque que.append(e) que.append que append e while que and i<n:
            now = que.popleft()
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = C[i]
                    i += 1
                    que.append(ne)
         que and i<n que i<n i n now = que.popleft() now que.popleft() que.popleft que popleft for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = C[i]
                    i += 1
                    que.append(ne)
         ne fordfs[now] fordfs now if W[ne] == -1:
                    W[ne] = C[i]
                    i += 1
                    que.append(ne)
         W[ne] == -1 W[ne] W ne -1 W[ne] = C[i] W[ne] W ne C[i] C i i += 1 i 1 que.append(ne) que.append que append ne return W W n n e e fordfs fordfs C C N = I() N I() I []for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] V = [[]for _ in range(N)] V [[]for _ in range(N)] for _ in range(N-1):
        A, B = LI()
        V[A-1].append(B-1)
        V[B-1].append(A-1)
     _ range(N-1) range N-1 N 1 A, B = LI() A LI() LI B V[A-1].append(B-1) [A-1].append [A-1] V A-1 A 1 append B-1 B 1 V[B-1].append(A-1) [B-1].append [B-1] V B-1 B 1 append A-1 A 1 C = LI() C LI() LI C.sort(reverse=True) C.sort C sort reverse=True reverse True e = 0 e 0 ans = bfs(N,e,V,C) ans bfs(N,e,V,C) bfs N e V C print(sum(ans)-C[0]) print sum(ans)-C[0] sum(ans) sum ans C[0] C 0 print(" ".join(map(str,ans))) print " ".join(map(str,ans)) " ".join " " join map(str,ans) map str ans return def examE():
    ans = 0
    print(ans)
    return examE ans = 0 ans 0 print(ans) print ans return def examF():
    ans = 0
    print(ans)
    return examF ans = 0 ans 0 print(ans) print ans return import sys,copy,bisect,itertools,heapq,math,random sys copy bisect itertools heapq math random from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) I def LI(): return list(map(int,sys.stdin.readline().split())) LI def LSI(): return list(map(str,sys.stdin.readline().split())) LSI def LS(): return sys.stdin.readline().split() LS def SI(): return sys.stdin.readline().strip() SI global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 mod2 = 998244353 mod2 998244353 inf = 10**18 inf 10**18 10 18 _ep = 10**(-12) _ep 10**(-12) 10 -12 chr(ord('a') + i) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) chr(ord('a') + i) chr ord('a') + i ord('a') ord 'a' i alphabet = [chr(ord('a') + i) for i in range(26)] alphabet [chr(ord('a') + i) for i in range(26)] if __name__ == '__main__':
    examD() __name__ == '__main__' __name__ '__main__' examD() examD """

""" def examD():
    def bfs(n, e, fordfs, C):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        i = 0
        W[e] = C[i]
        i += 1
        que = deque()
        que.append(e)
        while que and i<n:
            now = que.popleft()
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = C[i]
                    i += 1
                    que.append(ne)
        return W
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        A, B = LI()
        V[A-1].append(B-1)
        V[B-1].append(A-1)
    C = LI(); C.sort(reverse=True)
    e = 0
    ans = bfs(N,e,V,C)
    print(sum(ans)-C[0])
    print(" ".join(map(str,ans)))
    return def examD():
    def bfs(n, e, fordfs, C):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        i = 0
        W[e] = C[i]
        i += 1
        que = deque()
        que.append(e)
        while que and i<n:
            now = que.popleft()
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = C[i]
                    i += 1
                    que.append(ne)
        return W
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        A, B = LI()
        V[A-1].append(B-1)
        V[B-1].append(A-1)
    C = LI(); C.sort(reverse=True)
    e = 0
    ans = bfs(N,e,V,C)
    print(sum(ans)-C[0])
    print(" ".join(map(str,ans)))
    return examD def examF():
    ans = 0
    print(ans)
    return def examF():
    ans = 0
    print(ans)
    return examF global mod,mod2,inf,alphabet,_ep mod2 = 998244353 998244353 mod2 def examC():
    ans = 0
    print(ans)
    return def examC():
    ans = 0
    print(ans)
    return examC alphabet = [chr(ord('a') + i) for i in range(26)] [chr(ord('a') + i) for i in range(26)] alphabet mod = 10**9 + 7 10**9 + 7 mod inf = 10**18 10**18 inf def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS def examB():
    ans = 0
    print(ans)
    return def examB():
    ans = 0
    print(ans)
    return examB _ep = 10**(-12) 10**(-12) _ep def LI(): return list(map(int,sys.stdin.readline().split())) def LI(): return list(map(int,sys.stdin.readline().split())) LI def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I def examE():
    ans = 0
    print(ans)
    return def examE():
    ans = 0
    print(ans)
    return examE def LSI(): return list(map(str,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) LSI def SI(): return sys.stdin.readline().strip() def SI(): return sys.stdin.readline().strip() SI def examA():
    N = I()
    ans = 0
    print(ans)
    return def examA():
    N = I()
    ans = 0
    print(ans)
    return examA
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    def bfs(n, e, fordfs, C):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        i = 0
        W[e] = C[i]
        i += 1
        que = deque()
        que.append(e)
        while que and i<n:
            now = que.popleft()
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = C[i]
                    i += 1
                    que.append(ne)
        return W
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        A, B = LI()
        V[A-1].append(B-1)
        V[B-1].append(A-1)
    C = LI(); C.sort(reverse=True)
    e = 0
    ans = bfs(N,e,V,C)
    print(sum(ans)-C[0])
    print(" ".join(map(str,ans)))
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""