#include <iostream>
#include <string>
#include <algorithm>
#include  <set>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(i=0;i<n;i++)

int main() {
	ll a, b, n, d[10000]={}, e, f, g, h, i, j, c[10000], m, l, sum = 0;
	int s[10000][2];
	cin >> n;	
	rep(i, n-1) {
		cin >> s[i][0];
		cin >> s[i][1];
		s[i][0]--;
		s[i][1]--;
	}
	rep(i, n)cin >> c[i];
	sort(c, c + n);
	rep(i, n - 1)sum = sum + c[i];
	d[0] = c[n-1];
	for (i = n - 2; i >= 0; i--) {
		j = 0;
		e = 0;
		while ((j < n-1) && e==0) {
			g = s[j][0]; h = s[j][1];


			if (d[g] == 0 && d[h] >= c[i]) {

				d[g] = c[i];
				e = 1;
			}
			if (d[h] == 0 && d[g] >= c[i]) {
				d[h] = c[i];
				e=1;
			
			}
			j++;
		}
		
	}
	

	cout << sum << "\n";
	rep(i, n)cout << d[i] <<" ";

	cin >> n;
	return 0;
}