#include<bits/stdc++.h>

using namespace std;

int N, X[200009], t[200009], d[200009], col[200009];
vector < pair < int, int > > initV[200009];
vector < int > v[200009];

void initDfs (int nod, int tata)
{
    for (auto it : initV[nod])
        if (it.first != tata)
            t[it.first] = nod, d[it.first] = it.second,
            v[nod].push_back (it.first), initDfs (it.first, nod);
}

const pair < long long, int > pair0 = {1LL << 60, 0};
typedef pair < pair < long long, int >, pair < long long, int > > specialT;
specialT combine (specialT x, specialT y)
{
    specialT z;
    z.first = min (x.first, y.first);
    z.second = pair0;
    if (x.first.second != z.first.second && x.first < z.second)
        z.second = x.first;
    if (x.second.second != z.first.second && x.second < z.second)
        z.second = x.second;
    if (y.first.second != z.first.second && y.first < z.second)
        z.second = y.first;
    if (y.second.second != z.first.second && y.second < z.second)
        z.second = y.second;
    return z;
}
specialT addD (specialT x, int D)
{
    return {{x.first.first + D, x.first.second}, {x.second.first + D, x.second.second}};
}

specialT sub[200009], up[200009];
void dfsSub (int nod)
{
    sub[nod] = {{X[nod], col[nod]}, pair0};
    for (auto it : v[nod])
    {
        dfsSub (it);
        sub[nod] = combine (sub[nod], addD (sub[it], d[it]));
    }
}

void dfsUp (int nod)
{
    if (nod == 1) up[nod] = {pair0, pair0};
    for (auto it : v[nod])
        up[it] = addD (up[nod], d[it]),
        up[it] = combine (up[it], {{d[it] + X[nod], col[nod]}, pair0});
    for (int steps = 0; steps < 2; steps ++)
    {
        specialT sofar = {pair0, pair0};
        for (auto it : v[nod])
        {
            up[it] = combine (up[it], addD (sofar, d[it]));
            sofar = combine (sofar, addD (sub[it], d[it]));
        }
        reverse (v[nod].begin (), v[nod].end ());
    }
    for (auto it : v[nod])
        dfsUp (it);
}

pair < long long, int > amigo[200009];
void getAmigo ()
{
    dfsSub (1);
    dfsUp (1);
    for (int i=1; i<=N; i++)
        amigo[i] = pair0;
    for (int i=1; i<=N; i++)
    {
        up[i] = addD (up[i], X[i]), sub[i] = addD (sub[i], X[i]);
        specialT curr = combine (up[i], sub[i]);
        pair < long long, int > currP;
        if (curr.first.second == col[i]) currP = curr.second;
        else currP = curr.first;
        if (currP < amigo[col[i]])
            amigo[col[i]] = currP;
    }
}

int totalEdges;
long long MST = 0;
void addEdge (int x, int y, long long z)
{
    //printf ("%d %d %lld\n", x, y, z);
    totalEdges ++, MST += z;
}

int getColor (int x)
{
    if (col[x] == x) return x;
    return col[x] = getColor (col[x]);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &X[i]);
for (int i=1; i<N; i++)
{
    int x, y, z;
    scanf ("%d %d %d", &x, &y, &z);
    initV[x].push_back ({y, z});
    initV[y].push_back ({x, z});
}
initDfs (1, -1);
for (int i=1; i<=N; i++)
    col[i] = i;
while (totalEdges < N - 1)
{
    getAmigo ();
    vector < pair < int, int > > edges;
    for (int i=1; i<=N; i++)
        if (getColor (i) == i && (amigo[amigo[i].second].second != i || i < amigo[i].second))
            addEdge (i, amigo[i].second, amigo[i].first),
            edges.push_back ({i, amigo[i].second});
    for (auto it : edges)
    {
        it.first = getColor (it.first);
        it.second = getColor (it.second);
        if (it.first != it.second)
            col[it.first] = it.second;
    }
    for (int i=1; i<=N; i++)
        col[i] = getColor (i);
    //printf ("\n");
}
printf ("%lld\n", MST);
return 0;
}


Measured memory_bytes: 86772