N = int(input())
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
c = list(map(int,input().split()))
c.sort()
ans = sum(c) - max(c)
F = []
for i in range(1,N+1):
    n = len(G[i])
    if n == 1:
        F.append(i)
d = {}
i = 0
while i < N:
    x = F.pop(0)
    d[x] = c[i]
    i += 1
    if len(G[x]) > 0:
        y = G[x][0]
        G[y].remove(x)
        if len(G[y]) == 1:
            F.append(y)
ANS = []
for i in range(1,N+1):
    ANS.append(d[i])
print(ans)
print(*ANS) N = int(input()) N int(input()) int input() input [] for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [] G = [[] for i in range(N+1)] G [[] for i in range(N+1)] for i in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a) i range(N-1) range N-1 N 1 a,b = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b G[a].append(b) [a].append [a] G a append b G[b].append(a) [b].append [b] G b append a 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() c.sort c sort ans = sum(c) - max(c) ans sum(c) - max(c) sum(c) sum c max(c) max c F = [] F [] for i in range(1,N+1):
    n = len(G[i])
    if n == 1:
        F.append(i) i range(1,N+1) range 1 N+1 N 1 n = len(G[i]) n len(G[i]) len G[i] G i if n == 1:
        F.append(i) n == 1 n 1 F.append(i) F.append F append i d = {} d {} i = 0 i 0 while i < N:
    x = F.pop(0)
    d[x] = c[i]
    i += 1
    if len(G[x]) > 0:
        y = G[x][0]
        G[y].remove(x)
        if len(G[y]) == 1:
            F.append(y) i < N i N x = F.pop(0) x F.pop(0) F.pop F pop 0 d[x] = c[i] d[x] d x c[i] c i i += 1 i 1 if len(G[x]) > 0:
        y = G[x][0]
        G[y].remove(x)
        if len(G[y]) == 1:
            F.append(y) len(G[x]) > 0 len(G[x]) len G[x] G x 0 y = G[x][0] y G[x][0] [x] G x 0 G[y].remove(x) [y].remove [y] G y remove x if len(G[y]) == 1:
            F.append(y) len(G[y]) == 1 len(G[y]) len G[y] G y 1 F.append(y) F.append F append y ANS = [] ANS [] for i in range(1,N+1):
    ANS.append(d[i]) i range(1,N+1) range 1 N+1 N 1 ANS.append(d[i]) ANS.append ANS append d[i] d i print(ans) print ans print(*ANS) print *ANS ANS G = [[] for i in range(N+1)] [[] for i in range(N+1)] G i += 1 1 i N = int(input()) int(input()) N c = list(map(int,input().split())) list(map(int,input().split())) c ans = sum(c) - max(c) sum(c) - max(c) ans a,b = map(int,input().split()) map(int,input().split()) a F = [] [] F ANS = [] [] ANS n = len(G[i]) len(G[i]) n i = 0 0 i y = G[x][0] G[x][0] y x = F.pop(0) F.pop(0) x b = map(int,input().split()) map(int,input().split()) b d = {} {} d
N = int(input())
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
c = list(map(int,input().split()))
c.sort()
ans = sum(c) - max(c)
F = []
for i in range(1,N+1):
    n = len(G[i])
    if n == 1:
        F.append(i)
d = {}
i = 0
while i < N:
    x = F.pop(0)
    d[x] = c[i]
    i += 1
    if len(G[x]) > 0:
        y = G[x][0]
        G[y].remove(x)
        if len(G[y]) == 1:
            F.append(y)
ANS = []
for i in range(1,N+1):
    ANS.append(d[i])
print(ans)
print(*ANS)