#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<ll,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 500005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

// Union find
struct uf {
  vi d;
  uf(){}
  uf(int mx):d(mx,-1){}
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y]; d[y] = x;
    return true;
  }
  int size(int x) { return -d[root(x)];}
};
//

int n;
vi w;
vvi to, co;
uf t;

struct D {
  P a, b;
  D(P a=P(LINF,-1), P b=P(LINF,-1)):a(a),b(b) {}
  void add(ll x) {
    a.fi += x;
    b.fi += x;
  }
  void push(P x) {
    if (a.se == x.se) {
      mins(a,x);
      return;
    }
    mins(b,x);
    if (a > b) swap(a,b);
  }
  void push(D& x) {
    push(x.a);
    push(x.b);
  }
  P get(int x) {
    if (a.se == x) return b;
    return a;
  }
};

v(D) dp[MX];
P best[MX];
D pfs(int v, int p=-1) {
  D res;
  int g = t.root(v);
  rep(i,sz(to[v])) {
    int u = to[v][i];
    if (u == p) continue;
    D r = pfs(u,v);
    r.add(co[v][i]);
    dp[v][i] = r;
    res.push(r);
  }
  res.push(P(w[v],g));
  return res;
}
void dfs(int v, D& x, int p=-1) {
  int g = t.root(v);
  int m = sz(to[v]);
  rep(i,m) {
    if (to[v][i] == p) {
      x.add(co[v][i]);
      dp[v][i] = x;
    }
  }
  v(D) dl = dp[v];
  v(D)& dr = dp[v];
  rep(i,m-1) dl[i+1].push(dl[i]);
  drep(i,m-1) dr[i].push(dr[i+1]);
  D tot = dl.back(); tot.add(w[v]);
  mins(best[g], tot.get(g));
  rep(i,m) {
    int u = to[v][i];
    if (u == p) continue;
    D y(P(w[v],g));
    if (i) y.push(dl[i-1]);
    if (i < m-1) y.push(dr[i+1]);
    dfs(u,y,v);
  }
}


int main() {
  scanf("%d",&n);
  w = vi(n);
  to = co = vvi(n);
  cin>>w;
  rep(i,n-1) {
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    --a; --b;
    to[a].pb(b); co[a].pb(c);
    to[b].pb(a); co[b].pb(c);
  }
  rep(i,n) dp[i] = v(D)(sz(to[i]));
  t = uf(n);
  ll ans = 0;
  while (1) {
    vi rs;
    rep(i,n) if (t.root(i) == i) rs.pb(i);
    if (sz(rs) == 1) break;
    for (int r : rs) best[r] = P(LINF,-1);
    D emp;
    pfs(0); dfs(0,emp);
    for (int r : rs) {
      int v = best[r].se;
      if (t.unite(r,v)) {
        ans += best[r].fi;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}




















