#include <bits/stdc++.h>
using namespace std;
int size[3010], fa[3010], sum[3010], head[10010];
struct node {
  int x, y, next;
} e[3010];
int find(int x) {
  if (x != fa[x]) fa[x] = find(fa[x]);
  return fa[x];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    e[i].x = x;
    e[i].y = y;
    e[i].next = head[w];
    head[w] = i;
  }
  int s = 0;
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    size[i] = 1;
    scanf("%d", &sum[i]);
    s += sum[i];
  }
  for (int i = 1; i <= 10000; i++) {
    int p = head[i];
    while (p) {
      int x = find(e[p].x), y = find(e[p].y);
      fa[y] = x;
      size[x] += size[y];
      sum[x] += sum[y];
      if (size[x] + sum[x] > s) {
        printf("%d\n", i);
        return 0;
      }
      p = e[p].next;
    }
  }
  puts("0");
  return 0;
}
