#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define INF 10000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
int n,a[114514],b[114514],d[114514];
bool used[114514];
int now=0;
int ans[114514];
vector<int>v[114514];
void dfs(int x){
	used[x]=true;
	ans[x]=d[now];
	now++;
	for(int i:v[x]){
		if(!used[i]){
			dfs(i);
		}
	}
}
signed main(){
	cin>>n;
	rep(i,n-1){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
		v[a[i]].push_back(b[i]);
		v[b[i]].push_back(a[i]);
	}
	rep(i,n)cin>>d[i];
	
	sort(d,d+n,greater<int>());
	int sum=0;
	rep(i,n)if(i)sum+=d[i];
	cout<<sum<<endl;
	dfs(0);
	
	
	rep(i,n){
		cout<<ans[i];
		if(i==n-1)cout<<endl;
		else cout<<" ";
	}
	return 0;
}
