#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> graph[10000];
int c[10000];
int idx_c = 0;
int d[10000];

void dfs(int cur, int parent) {
  if (idx_c >= n || d[cur] != -1) {
    return;
  }
  d[cur] = c[idx_c];
  ++idx_c;
  for (int to: graph[cur]) {
    if (to == parent) {
      continue;
    }
    dfs(to, cur);
  }
}

int main() {
  cin>>n;
  for (int i=0; i<n-1; i++) {
    int a, b;
    cin>>a>>b;
    --a; --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  for (int i=0; i<n; i++) {
    cin>>c[i];
  }
  sort(c, c + n);
  reverse(c, c + n);
  for (int i=0; i<n; i++) d[i] = -1;
  dfs(0, -1);
  long long m = 0;
  for (int i=1; i<n; i++) m += c[i];
  cout<<m<<endl;
  for (int i=0; i<n; i++) {
    cout<<d[i];
    if (i != n-1) {
      cout<<" ";
    }
  }
  cout<<endl;
}