#include <bits/stdc++.h>
using namespace std;
const long long MXN = 3e3 + 10;
const long long MXM = 5e2 + 10;
const long long MX5 = 1e5 + 10;
const long long MX6 = 1e6 + 10;
const long long LOG = 20;
const long long INF = 8e18;
const double eps = 1e-9;
const long long MOD = 1e9 + 7;
long long power(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2, md) % md
                      : power(a * a % md, b / 2, md) % md));
}
long long bmm(long long a, long long b) {
  return (a % b == 0 ? b : bmm(b, a % b));
}
string base2(long long n) {
  string a = "";
  while (n >= 2) {
    a += (char)(n % 2 + '0');
    n /= 2;
  }
  a += (char)(n + '0');
  reverse((a).begin(), (a).end());
  return a;
}
long long n, m, Sum, X[MXN];
long long par[MXN], SZ[MXN], dp[MXN];
vector<long long> G[MXN], vec;
vector<pair<long long, pair<long long, long long> > > E;
bool vis[MXN], mark[MXN];
set<long long> M;
void init() {
  vec.clear();
  M.clear();
  for (int i = 1; i <= n; i++) {
    SZ[i] = 1;
    par[i] = i;
    vis[i] = 0;
    mark[i] = 0;
    dp[i] = X[i];
    G[i].clear();
    M.insert(i);
  }
  return;
}
long long Find(long long u) {
  if (par[u] == u) {
    return u;
  }
  par[u] = Find(par[u]);
  return par[u];
}
void Union(long long u, long long v) {
  long long p1 = Find(u), p2 = Find(v);
  if (p1 == p2) {
    return;
  }
  if (SZ[p1] > SZ[p2]) {
    par[p2] = p1;
    SZ[p1] += SZ[p2];
    dp[p1] += dp[p2];
    M.erase(p2);
  } else {
    par[p1] = p2;
    SZ[p2] += SZ[p1];
    dp[p2] += dp[p1];
    M.erase(p1);
  }
  return;
}
bool DFS1(long long u) {
  bool f = 1;
  mark[u] = 1;
  if (Sum - dp[u] < SZ[u]) return 0;
  for (auto v : G[u]) {
    if (!mark[v]) {
      if (DFS1(v) == 0) return 0;
    }
  }
  return f;
}
void DFS(long long u) {
  vis[u] = 1;
  Sum += dp[u];
  for (auto v : G[u]) {
    if (!vis[v]) {
      DFS(v);
    }
  }
  return;
}
bool check(long long x) {
  init();
  long long i = 0;
  while (i < m && E[i].first < x) {
    long long u = E[i].second.first, v = E[i].second.second;
    Union(u, v);
    i++;
  }
  while (i < m) {
    long long u = E[i].second.first, v = E[i].second.second;
    long long p1 = Find(u), p2 = Find(v);
    G[p1].push_back(p2);
    G[p2].push_back(p1);
    i++;
  }
  auto itr = M.begin();
  while (itr != M.end()) {
    long long now = *itr;
    if (G[now].empty()) return 0;
    vec.push_back(now);
    itr++;
  }
  for (auto u : vec) {
    if (!vis[u]) {
      Sum = 0;
      DFS(u);
      bool f = DFS1(u);
      if (!f) return 0;
    }
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  m = n - 1;
  for (int i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    E.push_back({w, {u, v}});
  }
  for (int i = 1; i <= n; i++) cin >> X[i];
  sort(((E)).begin(), ((E)).end());
  long long l = 0, r = 1e5;
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (check(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  cout << l;
  return 0;
}
