#include <bits/stdc++.h>
using namespace std;
const int N = 3050;
struct node {
  int x, y, c;
} E[N];
bool cmp(node x, node y) { return x.c < y.c; }
int fa[N], s[N], x[N];
int getf(int v) {
  if (v == fa[v]) return v;
  return fa[v] = getf(fa[v]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) scanf("%d%d%d", &E[i].x, &E[i].y, &E[i].c);
  sort(E + 1, E + n, cmp);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
    sum += x[i];
    fa[i] = i;
    s[i] = 1;
  }
  for (int i = 1; i < n; i++) {
    int u = getf(E[i].x), v = getf(E[i].y);
    fa[u] = v;
    s[v] += s[u];
    x[v] += x[u];
    if (s[v] > sum - x[v]) {
      printf("%d\n", E[i].c);
      return 0;
    }
  }
  printf("0");
}
