#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


int main() {
    int N;
    cin >> N;
    map<int, vector<int>> graph;
    map<int, int> edge_num_list;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
        edge_num_list[a]++;
        edge_num_list[b]++;
    }

    vector<pair<int, int>> sort_edge_num(N);
    int j = 0;
    for (auto& a : edge_num_list) {
        sort_edge_num[j] = make_pair(a.second, a.first);
        j++;
    }
    sort(sort_edge_num.begin(), sort_edge_num.end(), greater<pair<int, int>>());
    vint C(N);
    map<int, int, std::greater<int>> score_num;
    vint unique;
    rep(i, N) {
        cin >> C[i];
        score_num[C[i]] ++;
    }
    

    sort(C.begin(), C.end(), greater<int>());


    vint V_score(N + 1, -1);
    int i = 0;
    //sort(score_num.begin(), score_num.end(), greater<>());
   //score_num.
    //for (auto& sn : score_num) {
        
        int start;
        rep(i, N) {
            start = sort_edge_num[i].second;
            if (V_score[start] == -1)
                break;
        }
        deque<int> q;
        auto score_num_it = score_num.begin();
        q.push_back(start);
        V_score[start] = (*score_num_it).first;
        int max_num = (*score_num_it).second - 1;
        while (1) {
            if (q.size() <= 0 ) {
                break;
                /*if (max_num > 0) {
                    rep(i, N) {
                        start = sort_edge_num[i].second;
                        if (V_score[start] == -1)
                            break;
                    }
                    q.push_back(start);
                    V_score[start] = score_num.at(i);
                    
                    max_num--;
                }*/
               /* else {
                    break;
                }*/
            }
                
            auto nd = q.front();
            q.pop_front();

            for (auto adj : graph[nd]) {
                if (V_score[adj] == -1) {
                    
                    if (max_num == 0) {
                        score_num_it++;
                        max_num = (*score_num_it).second;

                    }
                    V_score[adj] = (*score_num_it).first;
                    max_num--;
                    q.push_back(adj);
                }
            }
        }
    //}

//    REP(i, 1, N) {
//        if (V_score[sort_edge_num[i].second] == -1)
//            V_score[sort_edge_num[i].second] = C[i];
//    }
    ll score = 0;
    for (auto& v : graph) {
        for (auto& adj : graph[v.first]) {
            score += min(V_score[v.first], V_score[adj]);
        }
    }

    score = 0;
    REP(i, 1, N) {
        score += C[i];
    }
    cout << score << endl;

    REP(i, 1, N + 1) {
        cout << V_score[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2560