#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define MAX 100005
typedef long long int ll;
typedef long int li;

vector<int> adj[MAX];
bool vis[MAX];
int d[MAX],c[MAX];

int k = 2,ans = 0;

void dfs(int u) {
    vis[u] = true;
    for(int v : adj[u]) {
        if(!vis[v]) {
            d[v] = c[k++];
            ans += d[v];
            dfs(v);
        } 
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    int n,x,y,num;
    cin>>n;
    for(int i=1;i<n;i++) {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    
    for(int i=1;i<=n;i++) cin>>c[i];
    sort(c+1,c+n+1,greater<int>());
    d[1] = c[1];
    
    dfs(1);
    
    cout<<ans<<"\n";
    for(int i=1;i<=n;i++) cout<<d[i]<<" ";
    return 0;
}