#include <bits/stdc++.h>
using namespace std;
int n;
struct st {
  int a;
  int b;
  int c;
};
vector<st> v;
bool cmp(st a, st b) { return a.c < b.c; }
vector<int> vv;
int belong[3002];
int siz[3002];
int sizz[3002];
inline int root(int b) {
  if (belong[b] == -1) return b;
  belong[b] = root(belong[b]);
  return belong[b];
}
void merge(int a, int b) {
  a = root(a);
  b = root(b);
  if (a == b) return;
  belong[a] = b;
  siz[b] += siz[a];
  sizz[b] += sizz[a];
}
int cap[3002];
bool ok(int val) {
  for (int i = 0; i < 3002; i++) belong[i] = -1, siz[i] = 1, sizz[i] = cap[i];
  for (int i = 0; i < v.size(); i++) {
    if (v[i].c >= val) {
      break;
    }
    merge(v[i].a, v[i].b);
  }
  vector<int> V;
  vector<int> S;
  int cap_sum = 0;
  for (int i = 0; i < n; i++) {
    if (i == root(i)) {
      V.push_back(siz[i]);
      S.push_back(sizz[i]);
      cap_sum += sizz[i];
    }
  }
  for (int i = 0; i < V.size(); i++) {
    int op = cap_sum - S[i];
    if (V[i] > op) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> n;
  if (n == 1) {
    puts("0");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    v.push_back({a, b, c});
    vv.push_back(c);
  }
  for (int i = 0; i < n; i++) scanf("%d", &cap[i]);
  sort(v.begin(), v.end(), cmp);
  sort(vv.begin(), vv.end());
  int mint = 0;
  int maxt = vv.size() - 1;
  while (mint + 1 < maxt) {
    int mid = (mint + maxt) >> 1;
    if (ok(vv[mid])) {
      mint = mid;
    } else {
      maxt = mid - 1;
    }
  }
  if (ok(vv[maxt])) {
    cout << vv[maxt] << endl;
  } else {
    cout << vv[mint] << endl;
  }
  return 0;
}
