#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e3 + 9;
int n, ans;
pair<int, pair<int, int> > edge[MAX_N];
int par[MAX_N];
int len[MAX_N];
int val[MAX_N];
int sum;
int root(int v) { return par[v] == v ? v : par[v] = root(par[v]); }
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> edge[i].second.first >> edge[i].second.second >> edge[i].first;
    edge[i].second.first--, edge[i].second.second--;
  }
  sort(edge, edge + n - 1);
  for (int i = 0; i < n; i++) {
    par[i] = i;
    len[i] = 1;
    cin >> val[i];
    sum += val[i];
  }
  ans = edge[0].first;
  for (int i = 0; i < n; i++) {
    int v = edge[i].second.first;
    int u = edge[i].second.second;
    val[root(u)] += val[root(v)];
    len[root(u)] += len[root(v)];
    par[root(v)] = root(u);
    if (sum - val[root(v)] < len[root(v)]) break;
    ans = edge[i + 1].first;
  }
  cout << ans << "\n";
  return 0;
}
