#include <bits/stdc++.h>
const int inf = (1ll << 31) - 1;
using namespace std;
int n;
int a[3300];
vector<pair<int, int> > v[3300];
int p[3300], sz[3300], sum[3300];
int aa = 0;
int cnt = 1;
void dfs(int x, int y, int num) {
  for (int i = 0; i < v[x].size(); i++) {
    int to = v[x][i].first;
    if (to == y) continue;
    if (p[to] == p[x]) dfs(to, x, num);
  }
  p[x] = num;
  sum[num] += a[x];
  sz[num]++;
}
vector<pair<int, pair<int, int> > > ans;
bool check() {
  for (int i = 0; i < cnt; i++) {
    if (sz[i] > aa - sum[i]) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    v[x].push_back(make_pair(y, c));
    v[y].push_back(make_pair(x, c));
    ans.push_back(make_pair(c, make_pair(x, y)));
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    aa += a[i];
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) {
    sz[p[ans[i].second.second]] = 0;
    sum[p[ans[i].second.second]] = 0;
    dfs(ans[i].second.second, ans[i].second.first, p[ans[i].second.second]);
    dfs(ans[i].second.first, ans[i].second.second, cnt);
    cnt++;
    if (check()) {
      cout << ans[i].first << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
