#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cassert>
#include <vector>
#include <unordered_map>
using namespace std;
struct bian{
	int next,point,w;
}b[410000];
const int N=210000;
const long long inf=1000000000000000000ll;
int p[N],len,x[N],father[N],whe[N],pd[N],n,pren,now,size[N],where;
long long d[23][N];
void ade(int k1,int k2,int k3){
	b[++len]=(bian){p[k1],k2,k3}; p[k1]=len;
}
void add(int k1,int k2,int k3){
	ade(k1,k2,k3); ade(k2,k1,k3);
}
long long f[N];
long long ans;
struct atom{
	int u,v;
	long long w;
}A[N];
int findfather(int k1){
	if (father[k1]==k1) return k1; return father[k1]=findfather(father[k1]);
}
int dfs1(int k1,int k2){
	size[k1]=1;
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (j!=k2&&pd[j]==0) size[k1]+=dfs1(j,k1);
	}
	return size[k1];
}
void dfs2(int k1,int k2){
	int num=n-size[k1];
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (j!=k2&&pd[j]==0){
			num=max(num,size[j]); dfs2(j,k1);
		}
	}
	if (num<now){
		now=num; where=k1;
	}
}
unordered_map<int,int>M[100];
struct atom2{
	long long f,g;
	int tagf,tagg;
	inline void update(long long k1,int t){
		if (t==tagf){
			f=min(f,k1); return;
		}
		if (k1<f){
			g=f; f=k1; tagg=tagf; tagf=t;
		} else if (k1<g){
			g=k1; tagg=t;
		}
	}
}cur;
vector<int>go,gow;
void update(int k1,long long k2){
	k2+=x[k1];
	if (father[k1]==cur.tagf){
		if (cur.g+k2<f[k1]){
			f[k1]=cur.g+k2; whe[k1]=cur.tagg;
		}
	}else{
		if (cur.f+k2<f[k1]){
			f[k1]=cur.f+k2; whe[k1]=cur.tagf;
		}
	}
}
vector<int>low[23][N];
void getdis(int k1,int k2,long long k3,int dd,int loc){
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (pd[j]==0&&j!=k2){
			getdis(j,k1,k3+b[i].w,dd,loc);
		}
	}
	d[dd][k1]=k3; low[dd][loc].push_back(k1);
}
void dfs3(int k1,int k2,int dd){
	update(k1,d[dd][k1]);
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (j!=k2&&pd[j]==0) dfs3(j,k1,dd);
	}
}
void dfs4(int k1,int k2,int dd){
	cur.update(d[dd][k1]+x[k1],father[k1]);
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (j!=k2&&pd[j]==0) dfs4(j,k1,dd);
	}
}
void solve(int k1,int dd){
	int k; int flag=0;
	if (M[dd][k1]==0){
		n=dfs1(k1,0); now=n; dfs2(k1,0); k=where; 
		M[dd][k1]=k; flag=1;
	} else k=M[dd][k1];
	pd[k]=1;
	if (flag){
		for (int i=p[k];i;i=b[i].next){
			int j=b[i].point;
			if (pd[j]==0) getdis(j,0,b[i].w,dd,j);
		}
	}
	//cout<<"asd "<<k<<endl;
	cur=(atom2){x[k],inf,father[k],0}; go.clear(); gow.clear();
	for (int i=p[k];i;i=b[i].next){
		int j=b[i].point;
		if (pd[j]==0){
			go.push_back(j); gow.push_back(b[i].w);
			for (int k:low[dd][j]) update(k,d[dd][k]);
			for (int k:low[dd][j])
				cur.update(d[dd][k]+x[k],father[k]);
		}
	}
	cur=(atom2){inf,inf,0,0};
	for (int i=go.size();i;i--){
		int j=go[i-1];
		if (pd[j]==0){
			for (int k:low[dd][j]) update(k,d[dd][k]);
			for (int k:low[dd][j])
				cur.update(d[dd][k]+x[k],father[k]);
		}
	}
	update(k,0);
	for (int i=p[k];i;i=b[i].next){
		int j=b[i].point;
		if (pd[j]==0) solve(j,dd+1);
	}
}
int compare(atom k1,atom k2){
	return k1.w<k2.w;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&x[i]);
	for (int i=1;i<n;i++){
		int k1,k2,k3; scanf("%d%d%d",&k1,&k2,&k3);
		add(k1,k2,k3);
	}
	for (int i=1;i<=n;i++) father[i]=i;
	int rem=n; pren=n;
	while (rem>1){
		memset(pd,0x00,sizeof pd);
		for (int i=1;i<=n;i++) f[i]=1e18;
		solve(1,0); n=pren;
	//	cout<<"asd "<<ans<<endl;
	//	for (int i=1;i<=n;i++) cout<<father[i]<<" "; cout<<endl;
	//	for (int i=1;i<=n;i++) cout<<f[i]<<" "; cout<<endl;
	//	for (int i=1;i<=n;i++) cout<<whe[i]<<" "; cout<<endl;
		int len=0;
		for (int i=1;i<=n;i++)
			if (father[i]!=i&&f[i]<f[father[i]]){
				f[father[i]]=f[i]; whe[father[i]]=whe[i];
			}
		for (int i=1;i<=n;i++) 
			if (father[i]==i)
				A[++len]=(atom){findfather(i),findfather(whe[i]),f[i]};
		sort(A+1,A+len+1,compare);
		for (int i=1;i<=len;i++){
			int k1=findfather(A[i].u),k2=findfather(A[i].v);
			if (k1!=k2){
				rem--; ans+=A[i].w; father[k1]=k2;
			}
		}
		for (int i=1;i<=n;i++) father[i]=findfather(father[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 195752