#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int n, ans, sum, a[N];
int sz[N], fa[N];
struct edge {
  int x, y, v;
  bool operator<(const edge &a) const { return v < a.v; }
} e[N];
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n - 1); i++)
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].v);
  sort(e + 1, e + n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[i]);
  for (int i = (int)(1); i <= (int)(n); i++) sz[i] = 1, fa[i] = i, sum += a[i];
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    ans = e[i].v;
    int x = get(e[i].x), y = get(e[i].y);
    fa[x] = y;
    sz[y] += sz[x];
    a[y] += a[x];
    if (sz[y] > sum - a[y]) break;
  }
  printf("%d\n", ans);
}
