/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
// #define INF 9e+18

/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

// int dx[] = {-1, 0, 1, 0};
// int dy[] = {0, -1, 0, 1};
int dx[] = {-1, 0, 1};
int dy[] = {-1, 0, 1};

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

bool _mysort(pair<int, int> a, pair<int, int> b) {
    if (a.second != b.second)
        return a.second > b.second;
    else {
        return a.first > b.first;
    }
}

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    vector<vector<int> > in(N);
    vector<int> c(N),isVisited(N,0);
    vector<pair<int,int> > h(N),ans;
    rep(i,N) h[i] = make_pair(i,0);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        in[a].push_back(b);
        in[b].push_back(a);
        h[a].second++;
        h[b].second++;
    }
    rep(i,N) cin >> c[i];
    sort(All(c),greater<int>());
    sort(All(h),_mysort);
    // rep(i,N) deb2(h[i].first,h[i].second);
    int first = h[0].first;
    int count = 0;
    int total = 0;
    ans.push_back(make_pair(first,c[count++]));
    isVisited[first] = 1;
    queue<int> q;
    q.push(first);
    while(!q.empty()){
        int now = q.front(); q.pop();
        for(auto i:in[now]){
            if(isVisited[i]==0){
                q.push(i);
                isVisited[i] = 1;
                ans.push_back(make_pair(i,c[count]));
                total += c[count++];
            }
        }
    }
    sort(All(ans));
    cout << total << nn;
    for(auto i:ans){
        cout << i.second << " ";
    }
    cout << nn;
    return 0;
}


Measured memory_bytes: 1280