#include <bits/stdc++.h>
using namespace std;
inline int Read() {
  char c = getchar();
  int num = 0;
  while ('0' > c || c > '9') c = getchar();
  while ('0' <= c && c <= '9') num = num * 10 + c - '0', c = getchar();
  return (num);
}
struct Edge {
  int x, y, w;
} e[3010];
int lm[3010], sz[3010], fa[3010], n, ans;
inline int Get(int x) {
  if (fa[x] == x) return (x);
  return (fa[x] = Get(fa[x]));
}
inline bool Check() {
  int nm = 0;
  for (int i = 1; i <= n; i++)
    if (Get(i) == i) nm += min(n - sz[i], lm[i]);
  return (nm >= n);
}
bool Cmpw(Edge a, Edge b) { return (a.w < b.w); }
int main() {
  n = Read();
  for (int i = 1; i < n; i++) e[i].x = Read(), e[i].y = Read(), e[i].w = Read();
  for (int i = 1; i <= n; i++) lm[i] = Read(), sz[i] = 1, fa[i] = i;
  sort(e + 1, e + n, Cmpw);
  for (int i = 1, j = 1; i < n; i = j) {
    for (; e[i].w == e[j].w; j < n) j++;
    for (int k = i; k < j; k++) {
      int fx = Get(e[k].x), fy = Get(e[k].y);
      sz[fx] += sz[fy], fa[fy] = fx, lm[fx] += lm[fy];
    }
    ans = e[i].w;
    if (!Check()) break;
  }
  printf("%d\n", ans);
}
