#include <bits/stdc++.h>
using i64 = long long;

std::vector<std::deque<int>> g;
std::vector<i64> c, r;

void dfs(int v, int p) {
    static int pos = 0;
    r[v] = c[pos++];
    for (int to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
    }
}

bool cmp(i64 a1,i64 a2){
    return a1>a2;
}

int main() {
    int n;
    std::cin >> n;
    g.resize(n); c.resize(n); r.resize(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        std::cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 0; i < n; i++) std::cin >> c[i];
    std::sort(c.begin(), c.end(), cmp);
    dfs(0, -1);
    std::cout << std::accumulate(c.begin() + 1, c.end(), 0ll) << std::endl;
    for (int i = 0; i < n; i++) std::cout << r[i] << " ";
    std::cout << std::endl;

    return 0;
}