Problem: Thought it is already the XXI century, the Mass Media isn't very popular in Walrusland. The cities get news from messengers who can only travel along roads. The network of roads in Walrusland is built so that it is possible to get to any city from any other one in exactly one way, and the roads' lengths are equal.

The North Pole governor decided to carry out an information reform. Several cities were decided to be chosen and made regional centers. Maintaining a region center takes k fishlars (which is a local currency) per year. It is assumed that a regional center always has information on the latest news.

For every city which is not a regional center, it was decided to appoint a regional center which will be responsible for keeping this city informed. In that case the maintenance costs will be equal to dlen fishlars per year, where len is the distance from a city to the corresponding regional center, measured in the number of roads along which one needs to go.

Your task is to minimize the costs to carry out the reform.

Input

The first line contains two given numbers n and k (1 ≤ n ≤ 180, 1 ≤ k ≤ 105).

The second line contains n - 1 integers di, numbered starting with 1 (di ≤ di + 1, 0 ≤ di ≤ 105).

Next n - 1 lines contain the pairs of cities connected by a road.

Output

On the first line print the minimum number of fishlars needed for a year's maintenance. On the second line print n numbers, where the i-th number will represent the number of the regional center, appointed to the i-th city. If the i-th city is a regional center itself, then you should print number i.

If there are several solutions to that problem, print any of them.

Examples

Input

8 10
2 5 9 11 15 19 20
1 4
1 3
1 7
4 6
2 8
2 3
3 5


Output

38
3 3 3 4 3 4 3 3 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int N;
long long DP[200][200][400];
long long m[200][200][400];
long long d[800];
pair<int, int> sol[200][2];
vector<vector<int> > grafo;
long long calcdp(int n, int dup, int ddown, int p);
void calcmn(int n, int dup, int ddown, int p) {
  m[n][dup][ddown] = DP[n][dup][ddown];
  if (ddown < 2 * N) {
    calcdp(n, dup, ddown + 1, p);
    m[n][dup][ddown] = min(m[n][dup][ddown], m[n][dup][ddown + 1]);
  }
}
long long calcdp(int n, int dup, int ddown, int p) {
  if (DP[n][dup][ddown] != -1) return DP[n][dup][ddown];
  long long &ans = DP[n][dup][ddown];
  ans = d[min(dup, ddown)];
  int vs = grafo[n].size();
  long long prev0 = 0, prev1 = 1000000000000000LL;
  int resto = (p != -1);
  if (vs - resto == 0 && (ddown > 0 && ddown < dup)) {
    ans = 1000000000000000LL;
    calcmn(n, dup, ddown, p);
    return 1000000000000000LL;
  }
  if (vs - resto == 0) {
    ans = d[min(ddown, dup)];
    calcmn(n, dup, ddown, p);
    return ans;
  }
  if (ddown) {
    for (int i = 0; i < (int)(vs); ++i) {
      long long act0 = 1000000000000000LL, act1 = 1000000000000000LL;
      int v = grafo[n][i];
      int ndup = min(N, min(dup + 1, ddown + 1));
      int dup1 = ndup;
      if (ddown == 1) dup1 = 0;
      if (v != p) {
        act1 = min(act1, prev0 + calcdp(v, dup1, ddown - 1, n));
        act1 = min(act1, prev1 + calcdp(v, dup1, ddown - 1, n));
        calcdp(v, ndup, ddown, n);
        act0 = min(act0, prev0 + m[v][ndup][ddown]);
        act1 = min(act1, prev1 + m[v][ndup][ddown]);
        prev1 = act1;
        prev0 = act0;
      }
    }
    ans += prev1;
  } else {
    long long resto = 0;
    for (int i = 0; i < (int)(vs); ++i) {
      int v = grafo[n][i];
      if (v != p) {
        long long act = 1000000000000000LL;
        for (int j = 0; j < (int)(2 * N + 1); ++j) {
          act = min(act, calcdp(v, 1, j, n));
        }
        resto += act;
      }
    }
    ans += resto;
  }
  calcmn(n, dup, ddown, p);
  return ans;
}
void construct(int n, int dup, int ddown, int p) {
  sol[n][0] = make_pair(dup, ddown);
  int vs = grafo[n].size();
  long long prev0 = 0, prev1 = 1000000000000000LL;
  if (ddown) {
    int first1 = 0;
    for (int i = 0; i < (int)(vs); ++i) {
      long long act0 = 1000000000000000LL, act1 = 1000000000000000LL;
      int v = grafo[n][i];
      int ndup = min(N, min(dup + 1, ddown + 1));
      int dup1 = ndup;
      if (ddown == 1) dup1 = 0;
      if (v != p) {
        int best = ddown;
        for (int j = ddown; j <= 2 * N; j++)
          if (calcdp(v, ndup, j, n) < calcdp(v, ndup, best, n)) best = j;
        act0 = min(act0, prev0 + m[v][ndup][ddown]);
        act1 = min(act1, prev1 + m[v][ndup][ddown]);
        sol[v][0] = make_pair(ndup, best);
        sol[v][1] = make_pair(ndup, best);
        if (prev1 + calcdp(v, dup1, ddown - 1, n) < act1) {
          sol[v][1] = make_pair(dup1, ddown - 1);
          act1 = min(act1, prev1 + calcdp(v, dup1, ddown - 1, n));
        }
        if (prev0 + calcdp(v, dup1, ddown - 1, n) < act1) {
          first1 = i;
          sol[v][1] = make_pair(dup1, ddown - 1);
          act1 = min(act1, prev0 + calcdp(v, dup1, ddown - 1, n));
        }
        prev1 = act1;
        prev0 = act0;
      }
    }
    for (int i = 0; i < (int)(vs); ++i) {
      int v = grafo[n][i];
      if (v != p) {
        if (i < first1) {
          construct(v, sol[v][0].first, sol[v][0].second, n);
        } else {
          construct(v, sol[v][1].first, sol[v][1].second, n);
        }
      }
    }
  } else {
    for (int i = 0; i < (int)(vs); ++i) {
      int v = grafo[n][i];
      if (v != p) {
        long long act = 1000000000000000LL;
        for (int j = 0; j < (int)(2 * N + 1); ++j) {
          if (act > calcdp(v, 1, j, n)) {
            sol[v][0] = make_pair(1, j);
            act = min(act, calcdp(v, 1, j, n));
          }
        }
        construct(v, sol[v][0].first, sol[v][0].second, n);
      }
    }
  }
}
int ans[200];
int main() {
  cin >> N >> d[0];
  for (int i = 0; i < (int)(N - 1); ++i) cin >> d[i + 1];
  grafo.resize(N);
  for (int i = 0; i < (int)(N - 1); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    grafo[a].push_back(b);
    grafo[b].push_back(a);
  }
  long long res = 1000000000000000LL;
  memset(DP, -1, sizeof(DP));
  for (int k = N; k <= 3 * N; k++) d[k] = 1000000;
  int bestj = 0;
  for (int j = 0; j < (int)(N + 1); ++j) {
    if (calcdp(0, N, j, -1) < res) {
      bestj = j;
    }
    res = min(res, calcdp(0, N, j, -1));
  }
  cout << res << endl;
  construct(0, N, bestj, -1);
  memset(ans, -1, sizeof(ans));
  queue<int> bfs;
  for (int i = 0; i < (int)(N); ++i) {
    if (!sol[i][0].second) {
      ans[i] = i + 1;
      bfs.push(i);
    }
  }
  while (!bfs.empty()) {
    int a = bfs.front(), vs = grafo[a].size();
    for (int i = 0; i < (int)(vs); ++i) {
      int next = grafo[a][i];
      if (ans[next] == -1) {
        ans[next] = ans[a];
        bfs.push(next);
      }
    }
    bfs.pop();
  }
  for (int i = 0; i < (int)(N); ++i) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}