#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (b < a) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = (int)(1e6) + 5;
const ll oo = 1e18;
int s[N];
vector < pii > g[N];
struct st
{
    ll ans;
    int color;
    st(void)
    {
        ans = oo;
        color = -1;
    }
    st(ll a,int b) : ans(a),color(b) {}
};
const st OO = st(oo,-1);
st operator + (st a,ll b)
{
    return st(a.ans + b,a.color);
}
bool operator < (st a,st b)
{
    if (a.ans != b.ans)
        return (a.ans < b.ans);
    return a.color < b.color;
}
pair < st , st > dp[N];
pair < st , st > operator + (pair < st , st > a,st b)
{
    if (a.fi.color == b.color)
        smin(a.fi.ans,b.ans);
    else
    if (a.se.color == b.color)
        smin(a.se.ans,b.ans);
    else
        a = min({a,mp(a.fi,b),mp(b,a.fi)});
    if (a.fi.ans > a.se.ans)
        swap(a.fi,a.se);
    return a;
}
int f[N];
int get(int k)
{
    return k == f[k] ? k : f[k] = get(f[k]);
}
void dfs(int node,int prev)
{
    for (auto it : g[node])
        if (it.fi != prev)
            dfs(it.fi,node),dp[node] = dp[node] + (dp[it.fi].fi + it.se) + (dp[it.fi].se + it.se) + st(s[it.fi] + it.se,get(it.fi));
}
int n;
st D[N];
ll answer = 0;
void pr(st ans)
{
    cerr << ans.ans << ' ' << ans.color << '\n';
}
void DFS(int node,int prev)
{
    for (auto it : g[node])
        if (it.fi != prev)
            dp[it.fi] = dp[it.fi] + (dp[node].fi + it.se) + (dp[node].se + it.se) + st(s[node] + it.se,get(node)),DFS(it.fi,node);
}
void go(void)
{
    for (int i = 1;i <= n;++i)
        dp[i] = mp(OO,OO),D[i] = OO;
    dfs(1,0);
    DFS(1,0);
    for (int i = 1;i <= n;++i)
        smin(D[get(i)],(dp[i].fi.color == get(i) ? dp[i].se : dp[i].fi) + s[i]);
    for (int i = 1;i <= n;++i)
        if (i == get(i) && get(i) != get(D[i].color))
            answer += D[i].ans,f[get(i)] = get(D[i].color);
    for (int i = 1;i <= n;++i)
        f[i] = get(i);
}
int main(void)
{
    cin>>n;
    for (int i = 1;i <= n;++i)
        cin>>s[i];
    for (int i = 1;i < n;++i)
    {
        int a,b,c;
        cin>>a>>b>>c;
        g[a].pb(mp(b,c));
        g[b].pb(mp(a,c));
    }
    for (int i = 1;i <= n;++i)
        f[i] = i;
    while (*min_element(f + 1,f + 1 + n) != *max_element(f + 1,f + 1 + n))
        go();
    cout << answer << '\n';
    return 0;
}
