#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> G[N], w[N];
struct node { long long d; int to; node(long long d = 1e18, int to = 0) : d(d), to(to) {} };
node operator + (const node &a, int x) { return node(a.d + x, a.to); }
bool operator < (const node &a, const node &b) {
	if (a.d != b.d) return a.d < b.d;
	return a.to < b.to;
}
int f[N], col[N], x[N];
int fat(int x) {
	if (f[x] == x) return x;
	return f[x] = fat(f[x]);
}
node cho1[N], cho2[N];
pair<node, node> pick_different_color(const vector<node> &child, int ban1 = -1, int ban2 = -1, int ban3 = -1) {
	node cho1 = node(), cho2 = node();
	for (int i = 0; i < (int) child.size(); ++ i) {
		if (child[i].to == ban1 || child[i].to == ban2 || child[i].to == ban3) continue;
		cho1 = child[i];
		for (int j = i + 1; j < (int) child.size(); ++ j) {
			if (child[j].to == ban1 || child[j].to == ban2 || child[j].to == ban3) continue;
			if (col[child[j].to] == col[cho1.to]) continue;
			cho2 = child[j];
			break;
		}
		break;
	}
	return {cho1, cho2};
}
int tick[N], Cnt[N], xxx;
int &cnt(int x) {
	if (tick[x] < xxx) {
		tick[x] = xxx;
		Cnt[x] = 0;
	}
	return Cnt[x];
}
void clean(vector<node> &child) {
	xxx ++;
	vector<node> yy;
	for (node x : child) {
		int c = col[x.to];
		if (cnt(c) < 2) {
			yy.push_back(x);
			cnt(c) ++;
		}
	}
	child.swap(yy);
}
void dfs_d(int x, int p) {
	vector<node> child;
	for (int i = 0; i < (int) G[x].size(); ++ i) {
		int w = ::w[x][i], u = G[x][i];
		if (u == p) continue;
		dfs_d(u, x);
		node tmp1 = cho1[u] + w, tmp2 = cho2[u] + w, tmp3 = node(::x[u], u) + w;
		if (tmp1.to) child.push_back(tmp1);
		if (tmp2.to) child.push_back(tmp2);
		if (tmp3.to) child.push_back(tmp3);
	}
	sort(child.begin(), child.end());
	clean(child);
	tie(cho1[x], cho2[x]) = pick_different_color(child);
}
void dfs_u(int x, int p, node up1, node up2, node up3) {
	vector<node> child;
	if (up1.to) child.push_back(up1);
	if (up2.to) child.push_back(up2);
	if (up3.to) child.push_back(up3);
	for (int i = 0; i < (int) G[x].size(); ++ i) {
		int w = ::w[x][i], u = G[x][i];
		if (u == p) continue;
		node tmp1 = cho1[u] + w, tmp2 = cho2[u] + w, tmp3 = node(::x[u], u) + w;
		if (tmp1.to) child.push_back(tmp1);
		if (tmp2.to) child.push_back(tmp2);
		if (tmp3.to) child.push_back(tmp3);
	}
	sort(child.begin(), child.end());
	clean(child);
	tie(cho1[x], cho2[x]) = pick_different_color(child);
	for (int i = 0; i < (int) G[x].size(); ++ i) {
		int w = ::w[x][i], u = G[x][i];
		if (u == p) continue;
		node s_tmp1 = cho1[u] + w, s_tmp2 = cho2[u] + w, s_tmp3 = node(::x[u], u) + w;
		node tmp1, tmp2, tmp3 = node(::x[x], x);
		tie(tmp1, tmp2) = pick_different_color(child, s_tmp1.to, s_tmp2.to, s_tmp3.to);
		dfs_u(u, x, tmp1 + w, tmp2 + w, tmp3 + w);
	}
}
pair<long long, pair<int, int>> compo_cho[N];
int tot;
long long ans;
void join(int x, int y, long long z) {
	x = fat(x), y = fat(y);
	if (x != y) {
		f[x] = y;
		tot --;
		ans += z;
	}
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i) scanf("%d", &x[i]);
	for (int i = 1; i < n; ++ i) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		G[a].push_back(b);
		G[b].push_back(a);
		w[a].push_back(c);
		w[b].push_back(c);
	}
	for (int i = 1; i <= n; ++ i) f[i] = i;
	tot = n;
	ans = 0;
	while (tot > 1) {
		for (int i = 1; i <= n; ++ i) col[i] = fat(i);
		dfs_d(1, 0);
		dfs_u(1, 0, node(), node(), node());
		for (int i = 1; i <= n; ++ i) compo_cho[i] = {1e18, {0, 0}};
		for (int i = 1; i <= n; ++ i) {
			node &tmp = cho1[i];
			if (col[tmp.to] == col[i]) tmp = cho2[i];
			if (tmp.to) {
				int u = i, v = tmp.to;
				long long d = x[i] + tmp.d;
				if (u > v) swap(u, v);
				compo_cho[col[i]] = min(compo_cho[col[i]], {d, {u, v}});
			}
		}
		for (int i = 1; i <= n; ++ i) if (col[i] == i) {
			auto tmp = compo_cho[i];
			if (tmp.second.first) {
				join(tmp.second.first, tmp.second.second, tmp.first);
			}
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 119204