#include <bits/stdc++.h>
using namespace std;
const int mxn = 3e5 + 5;
vector<pair<int, int> > g[mxn];
int n, w[mxn];
long long d[mxn][3];
void dfs(int u, int p) {
  d[u][1] = d[u][2] = w[u];
  long long mx1 = 0, mx2 = 0;
  for (auto t : g[u]) {
    int v = t.first, c = t.second;
    if (v == p) continue;
    dfs(v, u);
    d[u][0] = max(max(d[u][0], d[v][0]), max(d[v][1], d[v][2]));
    if (d[v][1] - c > mx1) {
      mx2 = mx1;
      mx1 = d[v][1] - c;
    } else if (d[v][1] - c > mx2) {
      mx2 = d[v][1] - c;
    }
  }
  d[u][1] += mx1;
  d[u][2] += mx1 + mx2;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &w[i]);
  for (int i = 1; i < n; ++i) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    g[u].push_back(pair<int, int>(v, c));
    g[v].push_back(pair<int, int>(u, c));
  }
  dfs(1, 1);
  return printf("%lld\n", max(d[1][0], max(d[1][1], d[1][2]))), 0;
}
