7 3
1 4 7
1 2 2
2 3 3
3 4 8
2 5 1
1 6 4
6 7 5
 10 2
1 5
5 3 2
8 4 8
7 6 9
7 10 1
10 1 4
9 5 1
5 8 2
7 2 9
6 5 6
 10 5
4 8 7 5 1
5 1 1
2 7 1
4 3 1
10 9 1
10 1 1
1 8 1
10 7 1
10 3 1
7 6 1
 10 9
9 7 6 10 3 5 2 8 1
9 4 10
10 8 3
3 6 2
5 1 8
5 2 5
1 10 10
6 7 1
9 1 7
1 6 3
 10 5
8 5 2 10 1
3 1 7
5 4 6
10 8 4
6 8 9
7 8 4
9 5 6
8 1 9
2 10 2
9 8 7

3 2
 2 3
 5 1
 0 1
 5 1

#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 333;
const long long linf = 1e18 + 333;
const int N = 1e5 + 5;
int n, m, dep[N], dad[N], far[N];
pair<int, int> max1[N], max2[N];
vector<pair<int, int> > v[N];
bool mon[N];
void dfs(int root, int x) {
  dad[x] = root;
  dep[x] = dep[root] + 1;
  max1[x] = max2[x] = pair<int, int>(-inf, 0);
  if (mon[x]) max1[x] = pair<int, int>(0, x);
  for (__typeof((v[x]).begin()) it = (v[x]).begin(); it != (v[x]).end(); it++) {
    int p = it->first;
    if (p == root) continue;
    int c = it->second;
    dfs(x, p);
    if (max1[p].first + c > max1[x].first) {
      max2[x] = max1[x];
      max1[x] = pair<int, int>(max1[p].first + c, max1[p].second);
    } else if (max1[p].first + 1 > max2[x].first)
      max2[x] = pair<int, int>(max1[p].first + c, max1[p].second);
  }
}
void dfs2(int root, int x, int up) {
  printf("x = %d up = %d\n", x, up);
  int down = max1[x].first;
  if (up > down) {
    far[x] = far[dad[x]];
    for (__typeof((v[x]).begin()) it = (v[x]).begin(); it != (v[x]).end();
         it++) {
      int p = it->first;
      if (p == root) continue;
      int c = it->second;
      dfs2(x, p, up + c);
    }
  } else {
    if (up == down or max1[x].first == max2[x].first) {
      far[x] = x;
      for (__typeof((v[x]).begin()) it = (v[x]).begin(); it != (v[x]).end();
           it++) {
        int p = it->first;
        if (p == root) continue;
        int c = it->second;
        dfs2(x, p, max1[x].first + c);
      }
    } else {
      for (__typeof((v[x]).begin()) it = (v[x]).begin(); it != (v[x]).end();
           it++) {
        int p = it->first;
        if (p == root) continue;
        int c = it->second;
        if (max1[p].first + c == max1[x].first) {
          far[x] = far[p];
          dfs2(x, p, max(up, max2[x].first + c));
        } else
          dfs2(x, p, max1[x].first + c);
      }
    }
  }
}
int main() {
  ios ::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x;
    cin >> x;
    mon[x] = 1;
  }
  for (int i = 1; i < n; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    v[x].push_back(pair<int, int>(y, c));
    v[y].push_back(pair<int, int>(x, c));
  }
  dfs(0, 1);
  dfs2(0, 1, 0);
  for (int i = 1; i <= n; i++)
    printf("i = %d far[i] = %d max1[i] = %d max2[i] = %d\n", i, far[i],
           max1[i].first, max2[i].first);
  return 0;
}
