#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000;
pair<int, pair<int, int> > lis[MAXN];
int n;
int pre[MAXN];
int p[MAXN], siz[MAXN];
int findPre(int p) {
  if (pre[p] != pre[pre[p]]) {
    pre[p] = findPre(pre[p]);
  }
  return pre[p];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d%d%d", &lis[i].second.first, &lis[i].second.second, &lis[i].first);
    lis[i].second.first--;
    lis[i].second.second--;
  }
  int tot = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &p[i]);
    tot += p[i];
    pre[i] = i;
    siz[i] = 1;
  }
  sort(lis, lis + (n - 1));
  for (int i = 0; i < n; ++i) {
    int a = findPre(lis[i].second.first);
    int b = findPre(lis[i].second.second);
    pre[b] = a;
    siz[a] += siz[b];
    p[a] += p[b];
    if (siz[a] > (tot - p[a])) {
      printf("%d\n", lis[i].first);
      return 0;
    }
  }
  return 0;
}
