#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#include <numeric>
#include <set>
#include <queue>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

const ll inf = 1e18;

struct DSU {
	vi p, s;
	DSU(int n) : p(n), s(n, 1) {
		iota(all(p), 0);
	}
	int get(int v) {
		return (p[v] == v ? v : p[v] = get(p[v]));
	}
	bool unite(int u, int v) {
		if ((u = get(u)) != (v = get(v))) {
			if (s[u] < s[v]) {
				swap(u, v);
			}
			s[u] += s[v];
			p[v] = u;
			return true;
		}
		return false;
	}
};

int n;
vi x;
vector<vector<pii>> g;
vi col;
ll ans;
vector<pair<ll, int>> mn1, mn2, opt;

void upd(pair<ll, int>& mn1, pair<ll, int>& mn2, pair<ll, int> y) {
	if (y < mn1) {
		if (y.second != mn1.second) {
			mn2 = mn1;
		}
		mn1 = y;
	}
	else if(y < mn2 && y.second != mn1.second) {
		mn2 = y;
	}
}

void dfs_dp(int v, int p) {
	upd(mn1[v], mn2[v], { x[v], col[v] });
	for (auto e : g[v]) {
		if (e.first != p) {
			dfs_dp(e.first, v);
			upd(mn1[v], mn2[v], { mn1[e.first].first + e.second, mn1[e.first].second });
			upd(mn1[v], mn2[v], { mn2[e.first].first + e.second, mn2[e.first].second });
		}
	}
}

void dfs_upd(int v, int p, pair<ll, int> up_mn1, pair<ll, int> up_mn2) {
	{
		auto _up_mn1 = up_mn1;
		auto _up_mn2 = up_mn2;
		upd(_up_mn1, _up_mn2, mn1[v]);
		upd(_up_mn1, _up_mn2, mn2[v]);
		_up_mn1.first += x[v];
		_up_mn2.first += x[v];
		if (_up_mn1.second != col[v]) {
			opt[col[v]] = min(opt[col[v]], _up_mn1);
		}
		if (_up_mn2.second != col[v]) {
			opt[col[v]] = min(opt[col[v]], _up_mn2);
		}
	}
	{
		int pt = 0;
		while (pt < sz(g[v]) && g[v][pt].first != p) {
			pt++;
		}
		if (pt < sz(g[v])) {
			g[v].erase(g[v].begin() + pt);
		}
	}
	upd(up_mn1, up_mn2, { x[v], col[v] });
	vector<pair<ll, int>> suf_min1(sz(g[v]) + 1), suf_min2(sz(g[v]) + 1);
	suf_min1.back() = { inf, -1 };
	suf_min2.back() = { inf, -1 };
	for (int i = sz(g[v]) - 1; i >= 0; i--) {
		suf_min1[i] = suf_min1[i + 1];
		suf_min2[i] = suf_min2[i + 1];
		upd(suf_min1[i], suf_min2[i], { mn1[g[v][i].first].first + g[v][i].second, mn1[g[v][i].first].second });
		upd(suf_min1[i], suf_min2[i], { mn2[g[v][i].first].first + g[v][i].second, mn2[g[v][i].first].second });
	}
	pair<ll, int> pref_min1 = { inf, -1 };
	pair<ll, int> pref_min2 = { inf, -1 };
	for (int i = 0; i < sz(g[v]); i++) {
		int to = g[v][i].first;
		int w = g[v][i].second;
		auto _up_mn1 = up_mn1;
		auto _up_mn2 = up_mn2;
		upd(_up_mn1, _up_mn2, pref_min1);
		upd(_up_mn1, _up_mn2, pref_min2);
		upd(_up_mn1, _up_mn2, suf_min1[i + 1]);
		upd(_up_mn1, _up_mn2, suf_min2[i + 1]);
		dfs_upd(to, v, { _up_mn1.first + w, _up_mn1.second }, { _up_mn2.first + w, _up_mn2.second });
		upd(pref_min1, pref_min2, { mn1[g[v][i].first].first + g[v][i].second, mn1[g[v][i].first].second });
		upd(pref_min1, pref_min2, { mn2[g[v][i].first].first + g[v][i].second, mn2[g[v][i].first].second });
	}
}

int32_t main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	x.resize(n);
	for (auto& val : x) cin >> val;
	g.resize(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v, w; cin >> u >> v >> w; --u; --v; g[u].pb({ v, w }); g[v].pb({ u, w });
	}
	DSU dsu(n);
	col.resize(n);
	while (true) {
		int lo = n, hi = -1;
		for (int u = 0; u < n; u++) {
			col[u] = dsu.get(u);
			lo = min(lo, col[u]);
			hi = max(hi, col[u]);
		}
		if (lo == hi) {
			break;
		}
		mn1.assign(n, { inf, -1 });
		mn2.assign(n, { inf, -1 });
		opt.assign(n, { inf, -1 });
		dfs_dp(0, -1);
		dfs_upd(0, -1, { inf, -1 }, { inf, -1 });
		for (int u = 0; u < n; u++) {
			if (opt[u].first != inf) {
				if (dsu.unite(u, opt[u].second)) {
					ans += opt[u].first;
				}
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 79000