#include <bits/stdc++.h>
using namespace std;
long long n, S;
vector<vector<pair<long long, long long> > > g;
vector<long long> p;
vector<long long> comp;
void dfs(long long v, long long c, long long x) {
  comp[v] = c;
  for (long long i = 0; i < g[v].size(); i++) {
    if (comp[g[v][i].first] == -1 && g[v][i].second < x) {
      dfs(g[v][i].first, c, x);
    }
  }
}
bool check(long long x) {
  comp.assign(n, -1);
  long long nComp = 0;
  for (long long i = 0; i < n; i++) {
    if (comp[i] == -1) {
      dfs(i, nComp, x);
      nComp++;
    }
  }
  vector<long long> sizes(nComp), sums(nComp);
  for (long long i = 0; i < n; i++) {
    sizes[comp[i]]++;
    sums[comp[i]] += p[i];
  }
  for (long long i = 0; i < nComp; i++) {
    if (sizes[i] + sums[i] > S) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n;
  g.resize(n);
  p.resize(n);
  for (long long i = 0; i < n - 1; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  for (long long i = 0; i < n; i++) cin >> p[i], S += p[i];
  long long l = 0, r = 1;
  while (check(r)) r *= 2;
  while (l + 1 <= r) {
    long long m = (l + r + 1) / 2;
    if (check(m))
      l = m;
    else
      r = m - 1;
  }
  cout << l << '\n';
  return 0;
}
