#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;

int N;
ll c[10000];
vector<vector<int>> edge;

int order[10000];
int scnt = 0;
bool used[10000];
void dfs(int pos) {
	for (int i = 0; i < edge[pos].size(); i++) {
		auto nxt = edge[pos][i];
		if (!used[nxt]) {
			order[nxt] = scnt;
			scnt++;
			used[nxt] = true;
			dfs(nxt);
		}
	}
}

int main() {
	cin >> N;
	edge.resize(N);
	for (int i = 0; i < N - 1; i++) {
		int c, d;
		cin >> c >> d;
		c--, d--;
		edge[c].push_back(d);
		edge[d].push_back(c);
	}
	ll M = 0;
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> c[i];
		ans += c[i];
		M = max(M, c[i]);
	}
	ans -= M;
	cout << ans << endl;
	sort(c, c + N);

	order[0] = 0, scnt = 1, used[0] = true;
	dfs(0);

	for (int i = 0; i < N; i++) {
		cout << c[N - 1 - order[i]] << " ";
	}
	cout << endl;
	return 0;
}