#include <bits/stdc++.h>
using namespace std;
int n, ans, total;
int app[3005], ata[3005], sz[3005];
pair<int, pair<int, int> > edge[3005];
int bul(int node) {
  if (ata[node] == node) return node;
  return ata[node] = bul(ata[node]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++)
    scanf("%d %d %d", &edge[i].second.first, &edge[i].second.second,
          &edge[i].first);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &app[i]);
    total += app[i];
    ata[i] = i;
    sz[i] = 1;
  }
  sort(edge + 1, edge + n);
  for (int i = 1; i < n; i++) {
    int a = bul(edge[i].second.first);
    int b = bul(edge[i].second.second);
    ata[a] = b;
    sz[b] += sz[a];
    app[b] += app[a];
    if (sz[b] > total - app[b]) {
      ans = edge[i].first;
      break;
    }
  }
  printf("%d", ans);
}
