#include <bits/stdc++.h>
using namespace std;
const int NR = 3005;
int n;
int sum;
struct Nd {
  int x, y, val;
  bool operator<(const Nd& A) const { return val < A.val; }
} t[NR];
int fa[NR], siz[NR], d[NR];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) siz[i] = 1, fa[i] = i;
  for (int i = 1; i < n; i++)
    t[i].x = read(), t[i].y = read(), t[i].val = read();
  for (int i = 1; i <= n; i++) d[i] = read(), sum += d[i];
  sort(t + 1, t + n);
  for (int i = 1; i < n; i++) {
    int fx = find(t[i].x), fy = find(t[i].y);
    siz[fx] += siz[fy], d[fx] += d[fy];
    fa[fy] = fx;
    if (siz[fx] > sum - d[fx]) {
      printf("%d\n", t[i].val);
      return 0;
    }
  }
  printf("%d\n", t[n - 1].val);
  return 0;
}
