#include <bits/stdc++.h>
using namespace std;
long w[200000], sz[200000], ttl[200000], ans, n;
vector<pair<long, pair<long, long> > > v;
long s, er, a, b;
long c, cur;
long gett(long x) {
  while (x != w[x]) x = w[x];
  return x;
}
void merg(long a, long b) {
  a = gett(a), b = gett(b);
  w[b] = a;
  sz[a] += sz[b];
  ttl[a] += ttl[b];
  if (sz[a] > s - ttl[a]) er = 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a >> b >> c;
    v.push_back(make_pair(c, make_pair(a, b)));
  }
  sort(v.begin(), v.end());
  for (int i = 1; i <= n; i++) {
    cin >> ttl[i];
    sz[i] = 1;
    s += ttl[i];
    w[i] = i;
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  ans = v[0].first;
  for (int i = 0; i < v.size();) {
    cur = i;
    while (cur < v.size() && v[cur].first == v[i].first) {
      merg(v[cur].second.first, v[cur].second.second);
      ++cur;
    }
    i = cur;
    if (i < v.size() && er == 0) ans = v[i].first;
  }
  cout << ans << endl;
  cin.get();
  cin.get();
  return 0;
}
