#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

void YNout(bool check){
	if(check)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return;
}

void Yayout(bool check){
	if(check) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	
	return;
}

/*
template <typename T>
void vecout(vector<T>& vecout_vec){
	
	rep(i,0,vecout_vec.size()){
		cout << vecout_vec.at(i) << endl;
	}
	
	return ;
}

template <typename T>
void vecin(vector<T>& vecin_vec, ll n){
	
	ll temp ;
	
	rep(i,0,n){
		cin >> temp;
		vecin_vec.push_back(temp);
		
	}
}

template <typename T>
void in(T& literal_in, T& literal_in2, ...){
	cin >> literal_in;
	in(literal_in2, ...);
	
	return;
}

template <typename T>
void in(T& literal_in){
	
	cin >> literal_in;
	
	return;
}

template <typename T>
void out(T& literal_out, T& literal_out2, ...){
	cout << literal_out << endl;
	out(literal_out2, ...);
	
	return;
}

template <typename T>
void out(T& literal_out){
	
	cout << literal_out << endl;
	
	return;
}
*/

ll n;
ll a[10001],b[10001];
ll c[10001];
struct deg_struct{
	ll cnt;
	ll deg_index;
	
	bool operator<(const deg_struct &another) const{
		return  cnt < another.cnt;
	}
	
	bool operator>(const deg_struct &another) const{
		return  cnt > another.cnt;
	}
};

struct edge_struct{
	ll deg_cnt;
	ll edge_index;
	
	bool operator<(const edge_struct &another) const{
		return deg_cnt < another.deg_cnt;
	}
	
	bool operator>(const edge_struct &another) const{
		return deg_cnt > another.deg_cnt;
	}
	
};

deg_struct deg[10001];
vector<edge_struct> G[10001];
bool is_visited[10001] = {false};
ll ans,index_num;
ll cost[10001];

void bfs(ll point){
	is_visited[point] = true;
	cost[point] = c[index_num];
	
	//cout << point <<  " ";
	index_num++;
	
	rep(i,0,G[point].size()){
		//cout << G[point].size() << endl;
		if(!is_visited[G[point][i].edge_index]){
			bfs(G[point][i].edge_index);
		}
	}
	return ;
}

signed main(){
	ans = 0;
	index_num = 0;
	
	cin >> n;
	
	rep(i,0,n){
		deg[i].cnt = 0;
		deg[i].deg_index = i;
	}
	
	rep(i,0,n-1){
		cin >> a[i] >> b[i];
		deg[a[i]-1].cnt++;
		deg[b[i]-1].cnt++;
	}
	rep(i,0,n){
		cin >> c[i];
	}
	
	rep(i,0,n-1){
		
		edge_struct e;
		e.deg_cnt = deg[b[i]-1].cnt;
		e.edge_index = b[i]-1;
		
		G[a[i]-1].push_back(e);
		
		e.deg_cnt = deg[a[i]-1].cnt;
		e.edge_index = a[i]-1;
		
		G[b[i]-1].push_back(e);
	}
	
	
	
	sort(deg,deg+n,greater<deg_struct>());
	sort(c,c+n,greater<ll>());
	
	/*
	rep(i,0,n){
		cout << c[i] << endl;
		
	}
	
	
	
	rep(i,0,n){
		rep(j,0,G[i].size()){
			cout << G[i][j].deg_cnt << " " << G[i][j].edge_index << "     ";
		}
		cout << endl;
	}
	
	*/
	
	
	
	rep(i,0,n){
		sort(G[i].begin(),G[i].end(),greater<edge_struct>());
	}
	
	
	bfs(deg[0].deg_index);
	
	rep(i,0,n-1){
		ans += min(cost[a[i]-1],cost[b[i]-1]);
	}
	
	cout << ans << endl;
	
	rep(i,0,n){
		cout << cost[i];
		if(i != n-1) cout << " ";
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 1792