N = int((input()))
ab = [list(map(int,input().split())) for _ in range(N-1)]
c = list(map(int,input().split()))
c.sort(reverse = True)

al = [[] for _ in range(N+1)]
for a,b in ab:
    al[a].append(b)
    al[b].append(a)

d = [0] * (N)
d[ab[0][0]-1] = c[0]
cnt = 1
child = al[ab[0][0]]
ans = 0
Check = [True] * (N+1)
Check[ab[0][0]] = False

while child and cnt < N:
    pi = int(child.pop())
    Check[pi] = False
    d[pi-1] = (c[cnt])
    ans += c[cnt]
    for i in al[pi]:
        if Check[i]:child.append(i)
    cnt += 1
    
print(ans)
print(' '.join(map(str,d))) N = int((input())) N int((input())) int input() input list(map(int,input().split())) for _ in range(N-1) for _ in range(N-1) _ range(N-1) range N-1 N 1 for _ in range(N-1) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ab = [list(map(int,input().split())) for _ in range(N-1)] ab [list(map(int,input().split())) for _ in range(N-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 [] for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [] al = [[] for _ in range(N+1)] al [[] for _ in range(N+1)] for a,b in ab:
    al[a].append(b)
    al[b].append(a) a b ab al[a].append(b) [a].append [a] al a append b al[b].append(a) [b].append [b] al b append a d = [0] * (N) d [0] * (N) [0] 0 N d[ab[0][0]-1] = c[0] d[ab[0][0]-1] d ab[0][0]-1 ab[0][0] [0] ab 0 0 1 c[0] c 0 cnt = 1 cnt 1 child = al[ab[0][0]] child al[ab[0][0]] al ab[0][0] [0] ab 0 0 ans = 0 ans 0 Check = [True] * (N+1) Check [True] * (N+1) [True] True N+1 N 1 Check[ab[0][0]] = False Check[ab[0][0]] Check ab[0][0] [0] ab 0 0 False while child and cnt < N:
    pi = int(child.pop())
    Check[pi] = False
    d[pi-1] = (c[cnt])
    ans += c[cnt]
    for i in al[pi]:
        if Check[i]:child.append(i)
    cnt += 1
     child and cnt < N child cnt < N cnt N pi = int(child.pop()) pi int(child.pop()) int child.pop() child.pop child pop Check[pi] = False Check[pi] Check pi False d[pi-1] = (c[cnt]) d[pi-1] d pi-1 pi 1 c[cnt] c cnt ans += c[cnt] ans c[cnt] c cnt for i in al[pi]:
        if Check[i]:child.append(i)
     i al[pi] al pi if Check[i]:child.append(i)
     Check[i] Check i cnt += 1 cnt 1 print(ans) print ans print(' '.join(map(str,d))) print ' '.join(map(str,d)) ' '.join ' ' join map(str,d) map str d pi = int(child.pop()) int(child.pop()) pi al = [[] for _ in range(N+1)] [[] for _ in range(N+1)] al ans = 0 0 ans c = list(map(int,input().split())) list(map(int,input().split())) c ans += c[cnt] c[cnt] ans cnt = 1 1 cnt d = [0] * (N) [0] * (N) d Check = [True] * (N+1) [True] * (N+1) Check ab = [list(map(int,input().split())) for _ in range(N-1)] [list(map(int,input().split())) for _ in range(N-1)] ab N = int((input())) int((input())) N child = al[ab[0][0]] al[ab[0][0]] child cnt += 1 1 cnt
N = int((input()))
ab = [list(map(int,input().split())) for _ in range(N-1)]
c = list(map(int,input().split()))
c.sort(reverse = True)

al = [[] for _ in range(N+1)]
for a,b in ab:
    al[a].append(b)
    al[b].append(a)

d = [0] * (N)
d[ab[0][0]-1] = c[0]
cnt = 1
child = al[ab[0][0]]
ans = 0
Check = [True] * (N+1)
Check[ab[0][0]] = False

while child and cnt < N:
    pi = int(child.pop())
    Check[pi] = False
    d[pi-1] = (c[cnt])
    ans += c[cnt]
    for i in al[pi]:
        if Check[i]:child.append(i)
    cnt += 1
    
print(ans)
print(' '.join(map(str,d)))
