#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<int> G[100010];
queue<int> que;
priority_queue<int> que2;
int a[100010];
void bfs(){
	while(que.size()){
		int x = que.front();
		que.pop();
		for(auto v:G[x]){
			if(a[v]==-1){
				int y = que2.top();
				a[v] = y; que2.pop();
				que.push(v);
			}
		}
	}
}
long long sum = 0;
void solve(int v, int p){
	for(auto x:G[v]){
		if(x!=p){
			sum += min(a[x],a[v]);
			solve(x,v);
		}
	}
}

int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n-1;i++){
		int s,t; cin >> s >> t;
		s--; t--;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	for(i=0;i<n;i++){
		a[i] = -1;
		int c; cin >> c; que2.push(c);
	}
	a[0] = que2.top();
	que2.pop(); que.push(0);
	bfs(); solve(0,-1);
	cout << sum << endl;
	for(i=0;i<n;i++){
		cout << a[i] << " ";
	}
	cout << endl;
}