#include <bits/stdc++.h>
using namespace std;
int f[3100], s[3100], a[3100], b[3100], n, sum = 0;
int find(int k) {
  if (k == f[k]) return k;
  return f[k] = find(f[k]);
}
struct rec {
  int x, y, z;
} q[3100];
bool cmp(rec a, rec b) { return a.z > b.z; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) scanf("%d%d%d", &q[i].x, &q[i].y, &q[i].z);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum += a[i];
  sort(q + 1, q + n + 1, cmp);
  for (int i = 2; i < n; i++)
    if (q[i].z != q[i - 1].z) {
      for (int j = 1; j <= n; j++) f[j] = j, s[j] = 1, b[j] = a[j];
      for (int j = i; j < n; j++) {
        int fx = find(q[j].x), fy = find(q[j].y);
        if (fx == fy) continue;
        f[fy] = fx;
        s[fx] += s[fy];
        b[fx] += b[fy];
        s[fy] = b[fy] = 0;
      }
      int pd = 1;
      for (int j = 1; j <= n; j++)
        if (find(j) == j) {
          if (s[j] > sum - b[j]) pd = 0;
        }
      if (pd) {
        cout << q[i - 1].z << endl;
        return 0;
      }
    }
  cout << q[n - 1].z << endl;
  return 0;
}
