#include<bits/stdc++.h>
using namespace std;

int N;
vector<int> G[10010];
vector<int> V;
int cnt = 0, l[100010];

int DFS(int v, int p = 0)
{
    l[v] = V[cnt++];
    for(int i = 0; i < G[v].size(); i++)if(G[v][i] != p)DFS(G[v][i], v);
    return 0;
}

int main()
{
    cin >> N;
    for(int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        V.push_back(a);
    }

    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());

    DFS(1);

    int ans = 0;
    for(int i = 1; i < V.size(); i++)ans += V[i];
    cout << ans << endl;
    for(int i = 1; i <= N; i++)
    {
        cout << l[i];
        if(i != N)cout << " ";
    }
    cout << endl;

    return 0;
}
