import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

def edges_to_pt(s,t,n,directed=False):
    pt = [[] for _ in range(n+1)]
    for i in range(len(s)):
        pt[s[i]].append(t[i])
        if directed==False:
            pt[t[i]].append(s[i])
    return pt

N = I()
a,b = Line(N-1,2)
c = III()

if N==1:
    print(c[0])
    print(c[0])
    exit()

c.sort()
M = sum(c[:-1])

pt = edges_to_pt(a,b,N)

used = [False]*(N+1)
ans = [0]*(N+1)
used[1] = True
ans[1] = c.pop()
q = [1]
while q:
    q1 = []
    for i in q:
        for j in pt[i]:
            if used[j]==False:
                used[j] = True
                ans[j] = c.pop()
                q1.append(j)
    q = q1

print(M)
print(*ans[1:]) import sys sys import math math from collections import defaultdict sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 def I(): return int(input()) I def II(): return map(int, input().split()) II def III(): return list(map(int, input().split())) III def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

################# Line if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

################# N<=0 N 0 return [[]]*num [[]]*num [[]] [] num elif num==1:
        return [I() for _ in range(N)]
     num==1 num 1 I() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) I() I return [I() for _ in range(N)] [I() for _ in range(N)] tuple(II()) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) tuple(II()) tuple II() II read_all = [tuple(II()) for _ in range(N)] read_all [tuple(II()) for _ in range(N)] return map(list, zip(*read_all)) map(list, zip(*read_all)) map list zip(*read_all) zip *read_all read_all N N num num def edges_to_pt(s,t,n,directed=False):
    pt = [[] for _ in range(n+1)]
    for i in range(len(s)):
        pt[s[i]].append(t[i])
        if directed==False:
            pt[t[i]].append(s[i])
    return pt edges_to_pt [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] pt = [[] for _ in range(n+1)] pt [[] for _ in range(n+1)] for i in range(len(s)):
        pt[s[i]].append(t[i])
        if directed==False:
            pt[t[i]].append(s[i])
     i range(len(s)) range len(s) len s pt[s[i]].append(t[i]) [s[i]].append [s[i]] pt s[i] s i append t[i] t i if directed==False:
            pt[t[i]].append(s[i])
     directed==False directed False pt[t[i]].append(s[i]) [t[i]].append [t[i]] pt t[i] t i append s[i] s i return pt pt s s t t n n directed=False directed False N = I() N I() I a,b = Line(N-1,2) a Line(N-1,2) Line N-1 N 1 2 b c = III() c III() III if N==1:
    print(c[0])
    print(c[0])
    exit() N==1 N 1 print(c[0]) print c[0] c 0 print(c[0]) print c[0] c 0 exit() exit c.sort() c.sort c sort M = sum(c[:-1]) M sum(c[:-1]) sum c[:-1] c :-1 -1 pt = edges_to_pt(a,b,N) pt edges_to_pt(a,b,N) edges_to_pt a b N used = [False]*(N+1) used [False]*(N+1) [False] False N+1 N 1 ans = [0]*(N+1) ans [0]*(N+1) [0] 0 N+1 N 1 used[1] = True used[1] used 1 True ans[1] = c.pop() ans[1] ans 1 c.pop() c.pop c pop q = [1] q [1] 1 while q:
    q1 = []
    for i in q:
        for j in pt[i]:
            if used[j]==False:
                used[j] = True
                ans[j] = c.pop()
                q1.append(j)
    q = q1 q q1 = [] q1 [] for i in q:
        for j in pt[i]:
            if used[j]==False:
                used[j] = True
                ans[j] = c.pop()
                q1.append(j)
     i q for j in pt[i]:
            if used[j]==False:
                used[j] = True
                ans[j] = c.pop()
                q1.append(j)
     j pt[i] pt i if used[j]==False:
                used[j] = True
                ans[j] = c.pop()
                q1.append(j)
     used[j]==False used[j] used j False used[j] = True used[j] used j True ans[j] = c.pop() ans[j] ans j c.pop() c.pop c pop q1.append(j) q1.append q1 append j q = q1 q q1 print(M) print M print(*ans[1:]) print *ans[1:] ans[1:] ans 1: 1 mod = 10**9 + 7 10**9 + 7 mod def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

################# def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

################# Line q = q1 q1 q used = [False]*(N+1) [False]*(N+1) used M = sum(c[:-1]) sum(c[:-1]) M pt = edges_to_pt(a,b,N) edges_to_pt(a,b,N) pt b = Line(N-1,2) Line(N-1,2) b q = [1] [1] q q1 = [] [] q1 def II(): return map(int, input().split()) def II(): return map(int, input().split()) II def III(): return list(map(int, input().split())) def III(): return list(map(int, input().split())) III def edges_to_pt(s,t,n,directed=False):
    pt = [[] for _ in range(n+1)]
    for i in range(len(s)):
        pt[s[i]].append(t[i])
        if directed==False:
            pt[t[i]].append(s[i])
    return pt def edges_to_pt(s,t,n,directed=False):
    pt = [[] for _ in range(n+1)]
    for i in range(len(s)):
        pt[s[i]].append(t[i])
        if directed==False:
            pt[t[i]].append(s[i])
    return pt edges_to_pt N = I() I() N def I(): return int(input()) def I(): return int(input()) I c = III() III() c ans = [0]*(N+1) [0]*(N+1) ans a,b = Line(N-1,2) Line(N-1,2) a def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

def edges_to_pt(s,t,n,directed=False):
    pt = [[] for _ in range(n+1)]
    for i in range(len(s)):
        pt[s[i]].append(t[i])
        if directed==False:
            pt[t[i]].append(s[i])
    return pt

N = I()
a,b = Line(N-1,2)
c = III()

if N==1:
    print(c[0])
    print(c[0])
    exit()

c.sort()
M = sum(c[:-1])

pt = edges_to_pt(a,b,N)

used = [False]*(N+1)
ans = [0]*(N+1)
used[1] = True
ans[1] = c.pop()
q = [1]
while q:
    q1 = []
    for i in q:
        for j in pt[i]:
            if used[j]==False:
                used[j] = True
                ans[j] = c.pop()
                q1.append(j)
    q = q1

print(M)
print(*ans[1:])