#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
const int N = 3005;
int siz[N], fa[N], a[N], sum, Flag = 1;
struct Edge {
  int u, v, w;
} e[10005];
bool operator<(const Edge &A, const Edge &B) { return A.w < B.w; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void Merge(int x, int y) {
  x = find(x), y = find(y);
  siz[x] += siz[y];
  fa[y] = x;
  a[x] += a[y];
  if (siz[x] > sum - a[x]) Flag = 0;
}
int main() {
  int n = read();
  for (int i = 1; i < n; ++i) e[i].u = read(), e[i].v = read(), e[i].w = read();
  sort(e + 1, e + n);
  for (int i = 1; i <= n; ++i)
    a[i] = read(), sum += a[i], fa[i] = i, siz[i] = 1;
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    if (Flag) ans = e[i].w;
    Merge(e[i].u, e[i].v);
  }
  cout << ans;
  return 0;
}
