#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int inf = 1000000;
struct edge {
  int x, y, k;
} e[3100];
int a[3100], n, tot, L[3100], R[3100], C[3100];
vector<int> E[3100];
struct Flow {
  int next[120000], e[120000], c[120000], head[13000], dis[13000], bfs[13000],
      len, s, t;
  Flow() { len = 1; }
  void reset(int source, int sink) {
    memset(head, 0, sizeof(head));
    s = source;
    t = sink;
    len = 1;
  }
  void addedge(int x, int y, int k) {
    next[++len] = head[x];
    head[x] = len;
    e[len] = y;
    c[len] = k;
    next[++len] = head[y];
    head[y] = len;
    e[len] = x;
    c[len] = 0;
  }
  bool build() {
    int l, r, i, x;
    memset(dis, 0, sizeof(dis));
    bfs[l = r = 1] = s;
    dis[s] = 1;
    while (l <= r) {
      x = bfs[l];
      for (i = head[x]; i; i = next[i])
        if (c[i] && !dis[e[i]]) {
          dis[e[i]] = dis[x] + 1;
          bfs[++r] = e[i];
        }
      l++;
    }
    return dis[t] != 0;
  }
  int dinic(int x, int v) {
    int flow = 0;
    if (x == t) return v;
    for (int i = head[x]; i; i = next[i])
      if (c[i] && dis[x] + 1 == dis[e[i]]) {
        int ff = dinic(e[i], min(v - flow, c[i]));
        c[i] -= ff;
        c[i ^ 1] += ff;
        flow += ff;
        if (flow == v) return flow;
      }
    dis[x] = -1;
    return flow;
  }
  int maxflow() {
    int ans = 0;
    while (build()) ans += dinic(s, inf);
    return ans;
  }
} flow;
void col(int x, int fa, int k) {
  int tmp = a[x];
  a[x] = k;
  for (int i : E[x])
    if (i != fa && a[i] == tmp) col(i, x, k);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    int x, y, k;
    scanf("%d%d%d", &x, &y, &k);
    e[i] = {x, y, k};
    E[x].push_back(y);
    E[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) scanf("%d", &C[i]);
  sort(e + 1, e + n, [](edge x, edge y) { return x.k > y.k; });
  tot = 1;
  for (int i = 1; i <= n; ++i) a[i] = 2;
  flow.reset(4 * n + 1, 4 * n + 2);
  for (int i = 1; i <= n - 1; ++i) {
    int fa = a[e[i].x] / 2, x = ++tot;
    assert(a[e[i].x] == a[e[i].y]);
    if (!L[fa])
      L[fa] = x;
    else
      R[fa] = x;
    flow.addedge(x, fa, inf);
    flow.addedge(fa + n, x + n, inf);
    col(e[i].x, e[i].y, x * 2);
    col(e[i].y, e[i].x, x * 2 + 1);
  }
  for (int i = 1; i <= n; ++i) {
    int fa = a[i] / 2;
    if (!L[fa])
      L[fa] = 2 * n + i;
    else
      R[fa] = 2 * n + i;
    flow.addedge(2 * n + i, fa, 1);
    flow.addedge(fa + n, 3 * n + i, inf);
    flow.addedge(4 * n + 1, 2 * n + i, 1);
    flow.addedge(3 * n + i, 4 * n + 2, C[i]);
  }
  int sum = 0;
  for (int i = 1; i <= n - 1; ++i) {
    int x = L[i + 1], y = R[i + 1];
    assert(x > 0);
    assert(y > 0);
    flow.addedge(x, y + n, inf);
    flow.addedge(y, x + n, inf);
    sum += flow.maxflow();
    if (sum == n) {
      printf("%d\n", e[i].k);
      return 0;
    }
  }
  printf("0\n");
  return 0;
}
