import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N = int(input())


node = [0 for i in range(N)]
neigh = [[] for j in range(N)]
ans = [0 for i in range(N)]
visited = [0 for i in range(N)]
k = 1

for i in range(N-1):
    ai,bi = map(int,input().split())
    node[ai-1] += 1
    node[bi-1] += 1
    neigh[ai-1].append(bi-1)
    neigh[bi-1].append(ai-1)
c = list(map(int,input().split()))
c.sort(reverse=True)
flag = False
def dfs(neighbor,start):
    global flag
    global k
    if sum(visited) == N:
        return 0

    for i in neighbor[start]:
        
        if visited[i] == 0:
            ans[i] = c[k]
            k += 1
            visited[i] = 1
            try:
                dfs(neighbor,i)
            except RuntimeError:
                flag = True
                return 0




m = max(node)
nn = node.index(m)
#nn = [node[i] for i in range(N) if node[i] == m][0]
visited[nn] = 1
ans[nn] = max(c)

dfs(neigh,nn)
"""
if flag:
    print(100)
    print(' '.join([str(i) for i in range(N)]))
    exit()
"""
ans2 = ' '.join([str(ans[i]) for i in range(N)])


print(sum(c)-max(c))
print(ans2) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 N = int(input()) N int(input()) int input() input 0 for i in range(N) for i in range(N) i range(N) range N for i in range(N) 0 node = [0 for i in range(N)] node [0 for i in range(N)] [] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [] neigh = [[] for j in range(N)] neigh [[] for j in range(N)] 0 for i in range(N) for i in range(N) i range(N) range N for i in range(N) 0 ans = [0 for i in range(N)] ans [0 for i in range(N)] 0 for i in range(N) for i in range(N) i range(N) range N for i in range(N) 0 visited = [0 for i in range(N)] visited [0 for i in range(N)] k = 1 k 1 for i in range(N-1):
    ai,bi = map(int,input().split())
    node[ai-1] += 1
    node[bi-1] += 1
    neigh[ai-1].append(bi-1)
    neigh[bi-1].append(ai-1) i range(N-1) range N-1 N 1 ai,bi = map(int,input().split()) ai map(int,input().split()) map int input().split() ().split () input split bi node[ai-1] += 1 node[ai-1] node ai-1 ai 1 1 node[bi-1] += 1 node[bi-1] node bi-1 bi 1 1 neigh[ai-1].append(bi-1) [ai-1].append [ai-1] neigh ai-1 ai 1 append bi-1 bi 1 neigh[bi-1].append(ai-1) [bi-1].append [bi-1] neigh bi-1 bi 1 append ai-1 ai 1 c = list(map(int,input().split())) c list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split c.sort(reverse=True) c.sort c sort reverse=True reverse True flag = False flag False def dfs(neighbor,start):
    global flag
    global k
    if sum(visited) == N:
        return 0

    for i in neighbor[start]:
        
        if visited[i] == 0:
            ans[i] = c[k]
            k += 1
            visited[i] = 1
            try:
                dfs(neighbor,i)
            except RuntimeError:
                flag = True
                return 0 dfs global flag global k if sum(visited) == N:
        return 0

     sum(visited) == N sum(visited) sum visited N return 0 0 for i in neighbor[start]:
        
        if visited[i] == 0:
            ans[i] = c[k]
            k += 1
            visited[i] = 1
            try:
                dfs(neighbor,i)
            except RuntimeError:
                flag = True
                return 0 i neighbor[start] neighbor start if visited[i] == 0:
            ans[i] = c[k]
            k += 1
            visited[i] = 1
            try:
                dfs(neighbor,i)
            except RuntimeError:
                flag = True
                return 0 visited[i] == 0 visited[i] visited i 0 ans[i] = c[k] ans[i] ans i c[k] c k k += 1 k 1 visited[i] = 1 visited[i] visited i 1 try:
                dfs(neighbor,i)
            except RuntimeError:
                flag = True
                return 0 except RuntimeError:
                flag = True
                return 0 flag = True flag True return 0 0 dfs(neighbor,i) dfs neighbor i neighbor neighbor start start m = max(node) m max(node) max node nn = node.index(m) nn node.index(m) node.index node index m visited[nn] = 1 visited[nn] visited nn 1 ans[nn] = max(c) ans[nn] ans nn max(c) max c dfs(neigh,nn) dfs neigh nn """
if flag:
    print(100)
    print(' '.join([str(i) for i in range(N)]))
    exit()
""" str(ans[i]) for i in range(N) for i in range(N) i range(N) range N for i in range(N) str(ans[i]) str ans[i] ans i ans2 = ' '.join([str(ans[i]) for i in range(N)]) ans2 ' '.join([str(ans[i]) for i in range(N)]) ' '.join ' ' join [str(ans[i]) for i in range(N)] print(sum(c)-max(c)) print sum(c)-max(c) sum(c) sum c max(c) max c print(ans2) print ans2 m = max(node) max(node) m ans = [0 for i in range(N)] [0 for i in range(N)] ans node = [0 for i in range(N)] [0 for i in range(N)] node c = list(map(int,input().split())) list(map(int,input().split())) c flag = False False flag visited = [0 for i in range(N)] [0 for i in range(N)] visited nn = node.index(m) node.index(m) nn ans2 = ' '.join([str(ans[i]) for i in range(N)]) ' '.join([str(ans[i]) for i in range(N)]) ans2 k = 1 1 k N = int(input()) int(input()) N def dfs(neighbor,start):
    global flag
    global k
    if sum(visited) == N:
        return 0

    for i in neighbor[start]:
        
        if visited[i] == 0:
            ans[i] = c[k]
            k += 1
            visited[i] = 1
            try:
                dfs(neighbor,i)
            except RuntimeError:
                flag = True
                return 0 def dfs(neighbor,start):
    global flag
    global k
    if sum(visited) == N:
        return 0

    for i in neighbor[start]:
        
        if visited[i] == 0:
            ans[i] = c[k]
            k += 1
            visited[i] = 1
            try:
                dfs(neighbor,i)
            except RuntimeError:
                flag = True
                return 0 dfs bi = map(int,input().split()) map(int,input().split()) bi neigh = [[] for j in range(N)] [[] for j in range(N)] neigh input = sys.stdin.readline sys.stdin.readline input ai,bi = map(int,input().split()) map(int,input().split()) ai
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N = int(input())


node = [0 for i in range(N)]
neigh = [[] for j in range(N)]
ans = [0 for i in range(N)]
visited = [0 for i in range(N)]
k = 1

for i in range(N-1):
    ai,bi = map(int,input().split())
    node[ai-1] += 1
    node[bi-1] += 1
    neigh[ai-1].append(bi-1)
    neigh[bi-1].append(ai-1)
c = list(map(int,input().split()))
c.sort(reverse=True)
flag = False
def dfs(neighbor,start):
    global flag
    global k
    if sum(visited) == N:
        return 0

    for i in neighbor[start]:
        
        if visited[i] == 0:
            ans[i] = c[k]
            k += 1
            visited[i] = 1
            try:
                dfs(neighbor,i)
            except RuntimeError:
                flag = True
                return 0




m = max(node)
nn = node.index(m)
#nn = [node[i] for i in range(N) if node[i] == m][0]
visited[nn] = 1
ans[nn] = max(c)

dfs(neigh,nn)
"""
if flag:
    print(100)
    print(' '.join([str(i) for i in range(N)]))
    exit()
"""
ans2 = ' '.join([str(ans[i]) for i in range(N)])


print(sum(c)-max(c))
print(ans2)