#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 123;
const int inf = 1e9;
const long double Pi = acos(-1);
const int mod = 95542721;
const long long Inf = 1e18;
int n, c[N];
struct edge {
  int u, v, c;
} e[N];
bool cmp(edge a, edge b) { return a.c < b.c; }
struct dsu {
  int p, sz;
} a[N];
bool fail;
int ans, second;
int get(int x) {
  if (a[x].p == x) return x;
  return a[x].p = get(a[x].p);
}
void Merge(int u, int v) {
  u = get(u);
  v = get(v);
  a[v].p = u;
  a[u].sz += a[v].sz;
  c[u] += c[v];
  if (a[u].sz > second - c[u]) {
    fail = 1;
  }
}
int main() {
  srand(time(0));
  cin >> n;
  for (int i = 1; i < n; i++) cin >> e[i].u >> e[i].v >> e[i].c;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    second += c[i];
  }
  sort(e + 1, e + n, &cmp);
  for (int i = 1; i <= n; i++) {
    a[i].p = i;
    a[i].sz = 1;
  }
  for (int i = 1; i < n; i++) {
    int j = i;
    while (j + 1 < n && e[j + 1].c == e[i].c) {
      j++;
    }
    for (int it = i; it <= j; it++) Merge(e[it].u, e[it].v);
    if (fail) {
      ans = e[i].c;
      break;
    }
    i = j;
  }
  cout << ans << endl;
  return 0;
}
