import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())


def func(v):
    if ans[v] != -1:
        return
    ans[v] = c[index]
    global index
    index += 1
    for next_v in graph[v]:
        if v == next_v:
            continue
        func(next_v)


n = II()
graph = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = MI()
    graph[u-1].append(v-1)
    graph[v-1].append(u-1)
c = sorted(LI(), reverse=True)
ans = [-1] * n
index = 0
func(0)
print(sum(c[1::]))
for i in range(n):
    print(ans[i], end=' ')
print() import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x def LI(): return [int(x) for x in sys.stdin.readline().split()] LI def MI(): return map(int, sys.stdin.readline().split()) MI def II(): return int(sys.stdin.readline()) II def func(v):
    if ans[v] != -1:
        return
    ans[v] = c[index]
    global index
    index += 1
    for next_v in graph[v]:
        if v == next_v:
            continue
        func(next_v) func if ans[v] != -1:
        return
     ans[v] != -1 ans[v] ans v -1 return ans[v] = c[index] ans[v] ans v c[index] c index global index index += 1 index 1 for next_v in graph[v]:
        if v == next_v:
            continue
        func(next_v) next_v graph[v] graph v if v == next_v:
            continue
         v == next_v v next_v continue func(next_v) func next_v v v n = II() n II() II [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] graph = [[] for _ in range(n)] graph [[] for _ in range(n)] for _ in range(n-1):
    u, v = MI()
    graph[u-1].append(v-1)
    graph[v-1].append(u-1) _ range(n-1) range n-1 n 1 u, v = MI() u MI() MI v graph[u-1].append(v-1) [u-1].append [u-1] graph u-1 u 1 append v-1 v 1 graph[v-1].append(u-1) [v-1].append [v-1] graph v-1 v 1 append u-1 u 1 c = sorted(LI(), reverse=True) c sorted(LI(), reverse=True) sorted LI() LI reverse=True reverse True ans = [-1] * n ans [-1] * n [-1] -1 n index = 0 index 0 func(0) func 0 print(sum(c[1::])) print sum(c[1::]) sum c[1::] c 1:: 1 for i in range(n):
    print(ans[i], end=' ') i range(n) range n print(ans[i], end=' ') print ans[i] ans i end=' ' end ' ' print() print n = II() II() n u, v = MI() MI() u v = MI() MI() v def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI(): return [int(x) for x in sys.stdin.readline().split()] LI def func(v):
    if ans[v] != -1:
        return
    ans[v] = c[index]
    global index
    index += 1
    for next_v in graph[v]:
        if v == next_v:
            continue
        func(next_v) def func(v):
    if ans[v] != -1:
        return
    ans[v] = c[index]
    global index
    index += 1
    for next_v in graph[v]:
        if v == next_v:
            continue
        func(next_v) func ans = [-1] * n [-1] * n ans c = sorted(LI(), reverse=True) sorted(LI(), reverse=True) c def II(): return int(sys.stdin.readline()) def II(): return int(sys.stdin.readline()) II index = 0 0 index def MI(): return map(int, sys.stdin.readline().split()) def MI(): return map(int, sys.stdin.readline().split()) MI graph = [[] for _ in range(n)] [[] for _ in range(n)] graph
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())


def func(v):
    if ans[v] != -1:
        return
    ans[v] = c[index]
    global index
    index += 1
    for next_v in graph[v]:
        if v == next_v:
            continue
        func(next_v)


n = II()
graph = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = MI()
    graph[u-1].append(v-1)
    graph[v-1].append(u-1)
c = sorted(LI(), reverse=True)
ans = [-1] * n
index = 0
func(0)
print(sum(c[1::]))
for i in range(n):
    print(ans[i], end=' ')
print()
