#include <bits/stdc++.h>
using namespace std;
int n, fa[3005], siz[3005], p[3005], sum;
struct node {
  int x, y, z;
} q[3005];
bool cmpp(node a, node b) { return a.z < b.z; }
int find(int x) {
  if (x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) scanf("%d%d%d", &q[i].x, &q[i].y, &q[i].z);
  sort(q + 1, q + n, cmpp);
  for (int i = 1; i <= n; i++)
    fa[i] = i, scanf("%d", &p[i]), siz[i] = 1, sum += p[i];
  for (int i = 1; i <= n - 1; i++) {
    int f1 = find(q[i].x), f2 = find(q[i].y);
    fa[f2] = f1;
    siz[f1] += siz[f2];
    p[f1] += p[f2];
    if (siz[f1] > sum - p[f1]) {
      printf("%d", q[i].z);
      return 0;
    }
  }
  printf("%d", q[n - 1].z);
  return 0;
}
