#include <bits/stdc++.h>
using namespace std;
const int N = 3030, M = 1e4 + 100;
int n, S, ans, u[N], v[N], w[N], par[N], sz[N], cnt[N];
bool bad;
vector<int> vec[M];
int g_par(int v) { return v == par[v] ? v : par[v] = g_par(par[v]); }
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> u[i] >> v[i] >> w[i];
    u[i]--;
    v[i]--;
    vec[w[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> sz[i];
    par[i] = i;
    cnt[i] = 1;
    S += sz[i];
  }
  for (int w = 0; w < M && bad == false; w++) {
    ans = w;
    for (int dex : vec[w]) {
      int U = g_par(u[dex]), V = g_par(v[dex]);
      sz[U] += sz[V];
      cnt[U] += cnt[V];
      par[V] = U;
      if (S - sz[U] < cnt[U]) bad = true;
    }
  }
  cout << (n == 1 ? 0 : ans);
  return 0;
}
