inpl = lambda: list(map(int,input().split()))
N = int(input())
partners = []
for i in range(N):
    partners.append(set())
for i in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    partners[a].add(b)
    partners[b].add(a)
C = sorted(inpl())

def goto_leaf(k):
    prev_k = None
    while len(partners[k]) > 1:
        for p in partners[k]:
            if p != prev_k:
                break
        prev_k = k
        k = p
    return k

def delete_leaf(k):
    for stem in partners[k]:
        break
    partners[stem].remove(k)
    return stem

M = sum(C[:-1])
D = [0]*N
k = 0
for i in range(N-1):
    k = goto_leaf(k)
    D[k] = C[i]
    k = delete_leaf(k)
D[k] = C[N-1]

print(M)
print(' '.join(map(str,D))) inpl = lambda: list(map(int,input().split())) inpl lambda: list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split N = int(input()) N int(input()) int input() input partners = [] partners [] for i in range(N):
    partners.append(set()) i range(N) range N partners.append(set()) partners.append partners append set() set for i in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    partners[a].add(b)
    partners[b].add(a) i range(N-1) range N-1 N 1 a, b = inpl() a inpl() inpl b a -= 1 a 1 b -= 1 b 1 partners[a].add(b) [a].add [a] partners a add b partners[b].add(a) [b].add [b] partners b add a C = sorted(inpl()) C sorted(inpl()) sorted inpl() inpl def goto_leaf(k):
    prev_k = None
    while len(partners[k]) > 1:
        for p in partners[k]:
            if p != prev_k:
                break
        prev_k = k
        k = p
    return k goto_leaf prev_k = None prev_k None while len(partners[k]) > 1:
        for p in partners[k]:
            if p != prev_k:
                break
        prev_k = k
        k = p
     len(partners[k]) > 1 len(partners[k]) len partners[k] partners k 1 for p in partners[k]:
            if p != prev_k:
                break
         p partners[k] partners k if p != prev_k:
                break
         p != prev_k p prev_k break prev_k = k prev_k k k = p k p return k k k k def delete_leaf(k):
    for stem in partners[k]:
        break
    partners[stem].remove(k)
    return stem delete_leaf for stem in partners[k]:
        break
     stem partners[k] partners k break partners[stem].remove(k) [stem].remove [stem] partners stem remove k return stem stem k k M = sum(C[:-1]) M sum(C[:-1]) sum C[:-1] C :-1 -1 D = [0]*N D [0]*N [0] 0 N k = 0 k 0 for i in range(N-1):
    k = goto_leaf(k)
    D[k] = C[i]
    k = delete_leaf(k) i range(N-1) range N-1 N 1 k = goto_leaf(k) k goto_leaf(k) goto_leaf k D[k] = C[i] D[k] D k C[i] C i k = delete_leaf(k) k delete_leaf(k) delete_leaf k D[k] = C[N-1] D[k] D k C[N-1] C N-1 N 1 print(M) print M print(' '.join(map(str,D))) print ' '.join(map(str,D)) ' '.join ' ' join map(str,D) map str D D = [0]*N [0]*N D inpl = lambda: list(map(int,input().split())) lambda: list(map(int,input().split())) inpl def delete_leaf(k):
    for stem in partners[k]:
        break
    partners[stem].remove(k)
    return stem def delete_leaf(k):
    for stem in partners[k]:
        break
    partners[stem].remove(k)
    return stem delete_leaf b = inpl() inpl() b b -= 1 1 b a -= 1 1 a k = delete_leaf(k) delete_leaf(k) k def goto_leaf(k):
    prev_k = None
    while len(partners[k]) > 1:
        for p in partners[k]:
            if p != prev_k:
                break
        prev_k = k
        k = p
    return k def goto_leaf(k):
    prev_k = None
    while len(partners[k]) > 1:
        for p in partners[k]:
            if p != prev_k:
                break
        prev_k = k
        k = p
    return k goto_leaf k = goto_leaf(k) goto_leaf(k) k partners = [] [] partners C = sorted(inpl()) sorted(inpl()) C N = int(input()) int(input()) N M = sum(C[:-1]) sum(C[:-1]) M k = 0 0 k a, b = inpl() inpl() a
inpl = lambda: list(map(int,input().split()))
N = int(input())
partners = []
for i in range(N):
    partners.append(set())
for i in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    partners[a].add(b)
    partners[b].add(a)
C = sorted(inpl())

def goto_leaf(k):
    prev_k = None
    while len(partners[k]) > 1:
        for p in partners[k]:
            if p != prev_k:
                break
        prev_k = k
        k = p
    return k

def delete_leaf(k):
    for stem in partners[k]:
        break
    partners[stem].remove(k)
    return stem

M = sum(C[:-1])
D = [0]*N
k = 0
for i in range(N-1):
    k = goto_leaf(k)
    D[k] = C[i]
    k = delete_leaf(k)
D[k] = C[N-1]

print(M)
print(' '.join(map(str,D)))