#include <bits/stdc++.h>
using namespace std;
# define ll long long int
									//nestedcode
vector<ll> adj[100000];				
ll vis[100000];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,i,a,c,t,r,aaa=0,mx=LLONG_MIN;
	cin>>n;
	ll aa[n+5];
	queue<ll> q;
	map<ll,ll> m;
	for(i=0;i<n-1;i++){
		cin>>a>>c;
		
		adj[a].push_back(c);
		adj[c].push_back(a);
	}
	for(i=1;i<=n;i++){
		cin>>aa[i];
		aaa+=aa[i];
		mx=max(mx,aa[i]);
	}
	sort(aa+1,aa+n+1);
	reverse(aa+1,aa+n+1);
	q.push(1);
	
	vis[1] = 1;
	t=1;
	m[1] = aa[t];
	t++;
	while(!q.empty()){
		r=q.front();
		q.pop();
		for(i=0;i<(ll)adj[r].size();i++){
			if(vis[adj[r][i]]==0){
				vis[adj[r][i]]=1;
				q.push(adj[r][i]);
				m[adj[r][i]] = aa[t];
				t++;
			}
		}
	}
	cout<<aaa-mx<<endl;
	for(i=1;i<=n;i++){
		cout<<m[i]<<" ";
	}
}
	
	