#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, z;
} e[5010];
bool cmp(const node& a, const node& b) { return a.z < b.z; }
int f[5010];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int n, bz[5010], sz[5010];
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) cin >> e[i].x >> e[i].y >> e[i].z;
  int tot = 0;
  for (int i = 1; i <= n; i++) cin >> sz[i], f[i] = i, tot += sz[i], bz[i] = 1;
  sort(e + 1, e + n, cmp);
  int ans = e[n - 1].z;
  bool flag = true;
  for (int i = 1; i < n;) {
    int j = i;
    for (; i < n && e[i].z == e[j].z; i++) {
      int fx = find(e[i].x), fy = find(e[i].y);
      f[fy] = fx;
      sz[fx] += sz[fy];
      bz[fx] += bz[fy];
      if (bz[fx] > tot - sz[fx]) flag = false;
    }
    if (!flag) {
      ans = e[j].z;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
