#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
const int maxn = 40001;
pair<int, pair<int, int> > edge[maxn];
int sz[maxn], f[maxn];
int lim[maxn];
int n;
int find(int k) {
  if (f[k] != k) f[k] = find(f[k]);
  return f[k];
}
int main() {
  scanf("%d", &n);
  if (n == 1) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n - 1; i++)
    scanf("%d%d%d", &edge[i].second.first, &edge[i].second.second,
          &edge[i].first);
  sort(edge + 1, edge + n);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &lim[i]);
    f[i] = i;
    sz[i] = 1;
    sum += lim[i];
  }
  int ans = edge[1].first;
  int mx = 1;
  for (int i = 1; i < n; i++) {
    int j;
    for (j = i; j < n && edge[i].first == edge[j].first; j++) {
      int fx = find(edge[j].second.first);
      int fy = find(edge[j].second.second);
      f[fx] = fy;
      sz[fy] += sz[fx];
      lim[fy] += lim[fx];
      if (sz[mx] < sz[fy]) mx = fy;
    }
    if (j < n && sum - lim[mx] >= sz[mx]) ans = edge[j].first;
    i = j - 1;
  }
  cout << ans << endl;
}
