#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int x[N], y[N], z[N], a[N], s, size1[N], size2[N], n, f[N];
int find(int x) {
  if (x == f[x]) return x;
  return f[x] = find(f[x]);
}
int pd(int val) {
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i < n; i++)
    if (z[i] < val) f[find(x[i])] = find(y[i]);
  memset(size1, 0, sizeof size1);
  memset(size2, 0, sizeof size2);
  for (int i = 1; i <= n; i++) size1[find(i)]++, size2[find(i)] += a[i];
  for (int i = 1; i <= n; i++)
    if (find(i) == i && s - size2[i] < size1[i]) return 0;
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) scanf("%d%d%d", &x[i], &y[i], &z[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), s += a[i];
  int l = 0, r = 10000;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    if (pd(mid))
      l = mid;
    else
      r = mid - 1;
  }
  printf("%d\n", l);
}
