#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}


struct uf{
  static const int MAXN=200005;
  int par[MAXN];
  int size[MAXN];
  void init(){
    memset(par,-1,sizeof(par));
    REP(i,MAXN) size[i]=1;
  }
  int root(int a){
    if(par[a]==-1) return a;
    return par[a]=root(par[a]);
  }
  void unite(int a,int b){
    a=root(a);b=root(b);
    if(a==b) return;
    if(size[a]<size[b]) swap(a,b);

    par[b]=a;
    size[a]+=size[b];
  }
  bool same(int a,int b){
    return root(a)==root(b);
  }
};

uf u;
const lint INF=1e18;
int n;
vector<pi> g[200005];
int ar[200005];
int col[200005];

void merge(vector<pair<lint,pi> >& A,pair<lint,pi> b,lint c){
  b.fr+=c;
  A.pb(b);
  sort(ALL(A));
  if(A.size()<=1) return;
  if(A[0].sc.sc==A[1].sc.sc) A.erase(A.begin()+1);
  else if(A.size()>2) A.pop_back();
}
vector<pair<lint,pi> > ch[200005];//(cost,(vertex,color));

void rec(int v,int p){
  ch[v].clear();
  ch[v].pb({ar[v],{v,col[v]}});
  for(auto e:g[v]){
    if(e.fr==p) continue;
    rec(e.fr,v);
    for(auto e2:ch[e.fr]) merge(ch[v],e2,e.sc);
  }
}

lint ans;

int K;
pair<lint,pi> es[200005];

pair<lint,pi>adj[200005];
void rec2(int v,int p,vector<pair<lint,pi> >top){
  vector<vector<pair<lint,pi> > > lef={top},rig;
  merge(lef[0],{ar[v],{v,col[v]}},0);

  rig=lef;
  int m=0;
  for(auto e:g[v]){
    if(e.fr==p) continue;
    lef.pb(lef.back());
    for(auto e2:ch[e.fr]) merge(lef.back(),e2,e.sc);
    ++m;
  }

  if(lef.back()[0].sc.sc!=col[v]) chmin(adj[col[v]],{lef.back()[0].fr+ar[v],{v,lef.back()[0].sc.fr}});
  else chmin(adj[col[v]],{lef.back()[1].fr+ar[v],{v,lef.back()[1].sc.fr}});

  for(int i=(int)g[v].size()-1;i>=0;--i){
    auto e=g[v][i];
    if(e.fr==p) continue;
    rig.pb(rig.back());
    for(auto e2:ch[e.fr]) merge(rig.back(),e2,e.sc);
  }

  int i=0;
  for(auto e:g[v]){
    if(e.fr==p) continue;
    vector<pair<lint,pi> >tmp=lef[i];
    for(auto e2:rig[m-i-1]) merge(tmp,e2,0);

    for(auto& e2:tmp) e2.fr+=e.sc;

    rec2(e.fr,v,tmp);
    ++i;
  }
}

int main(){
  cin>>n;
  REP(i,n) scanf("%d",&ar[i]);
  REP(i,n-1){
    int a,b,c;scanf("%d%d%d",&a,&b,&c);--a;--b;
    g[a].pb({b,c});
    g[b].pb({a,c});
  }
  REP(i,n) col[i]=i;
  u.init();
  while(1){
    unordered_set<int> S;
    REP(i,n) S.insert(col[i]),adj[i]={INF,{-1,-1}};
    if(S.size()==1) break;
    K=0;
    rec(0,-1);
    rec2(0,-1,{});
    REP(i,n) if(adj[i].fr!=INF){
      int a=adj[i].sc.fr,b=adj[i].sc.sc;
      if(!u.same(a,b)){
        u.unite(a,b);
        ans+=adj[i].fr;
      }
    }
    REP(i,n) col[i]=u.root(i);
  }
  cout<<ans<<endl;
  return 0;
}





Measured memory_bytes: 203336