#include <bits/stdc++.h>
using namespace std;
struct edge {
  int fr, to, val;
  bool operator<(const edge &o) const { return val < o.val; }
} e[2000100];
int n, m, x, y, z, fa[2000100], cnt[2000100], sum, siz[2000100], ans, flag = 1;
int gf(int u) { return u == fa[u] ? u : fa[u] = gf(fa[u]); }
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) scanf("%d %d %d", &e[i].fr, &e[i].to, &e[i].val);
  for (int i = 1; i <= n; i++)
    scanf("%d", &cnt[i]), sum += cnt[i], fa[i] = i, siz[i] = 1;
  sort(e + 1, e + n);
  for (int i = 1; i < n; i++) {
    if (flag) ans = e[i].val;
    int f1 = gf(e[i].fr), f2 = gf(e[i].to);
    fa[f1] = f2, siz[f2] += siz[f1], cnt[f2] += cnt[f1];
    if (siz[f2] > sum - cnt[f2]) flag = 0;
  }
  printf("%d\n", ans);
  return 0;
}
