#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

int N;
vector<int> X;
vector<vector<pii> > adj;

struct DSU {
    vector<int> par, rnk;
    void init() {
        for(int i = 0; i < N; i++) {
            par.push_back(i);
            rnk.push_back(0);
        }
    }
    int f(int u) {
        if(par[u] == u) return u;
        else return par[u] = f(par[u]);
    }
    void mrg(int u, int v) {
        u = f(u);
        v = f(v);
        if(u == v) return;
        if(rnk[u] < rnk[v]) swap(u, v);
        par[v] = u;
        if(rnk[u] == rnk[v]) rnk[u]++;
    }
} dsu;

vector<pli> dp1[2], dp2[2];

void relax(pli &mn1, pli &mn2, pli &tmp) {
    if(mn1 > tmp) {
        if(mn1.second != tmp.second) mn2 = mn1;
        mn1 = tmp;
    }
    else if(mn2 > tmp) {
        if(mn1.second != tmp.second) mn2 = tmp;
    }
}

void dfs1(int u, int p) {
    pli mn1 = pli(1e18, 1e9);
    pli mn2 = pli(1e18, 1e9);
    pli tmp;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i].first;
        ll w = adj[u][i].second;
        if(v == p) continue;
        dfs1(v, u);

        tmp = pli(X[u] + X[v] + w, dsu.f(v));
        relax(mn1, mn2, tmp);

        tmp = dp1[0][v];
        tmp.first += w - X[v] + X[u];
        relax(mn1, mn2, tmp);

        tmp = dp1[1][v];
        tmp.first += w - X[v] + X[u];
        relax(mn1, mn2, tmp);
    }
    dp1[0][u] = mn1;
    dp1[1][u] = mn2;
}

void dfs2(int u, int p) {
    relax(dp2[0][u], dp2[1][u], dp1[0][u]);
    relax(dp2[0][u], dp2[1][u], dp1[1][u]);

    pli tmp;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i].first;
        ll w = adj[u][i].second;
        if(v == p) continue;

        tmp = pli(X[u] + X[v] + w, dsu.f(u));
        relax(dp2[0][v], dp2[1][v], tmp);

        tmp = dp2[0][u];
        tmp.first += w - X[u] + X[v];
        relax(dp2[0][v], dp2[1][v], tmp);

        tmp = dp2[1][u];
        tmp.first += w - X[u] + X[v];
        relax(dp2[0][v], dp2[1][v], tmp);

        dfs2(v, u);
    }
}

map<int, pli> Mn;
int cnt;
ll ans;

void solve() {
    dp1[0] = dp1[1] = vector<pli>(N, pli(1e18, 1e9));
    dp2[0] = dp2[1] = vector<pli>(N, pli(1e18, 1e9));
    dfs1(0, -1);
    dfs2(0, -1);

    Mn.clear();
    for(int u = 0; u < N; u++) {
        pli tmp = dp2[0][u].second == dsu.f(u)? dp2[1][u] : dp2[0][u];
        if(Mn.find(dsu.f(u)) == Mn.end() || Mn[dsu.f(u)] > tmp) Mn[dsu.f(u)] = tmp;
    }
    for(map<int, pli>::iterator it = Mn.begin(); it != Mn.end(); it++) {
        int u = it->first;
        int v = it->second.second;
        ll w = it->second.first;
        if(dsu.f(u) == dsu.f(v)) continue;
        dsu.mrg(u, v);
        ans += w;
        cnt++;
    }
}

int main() {
    scanf("%d", &N);

    X.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &X[i]);
    }

    adj.resize(N);
    for(int i = 0; i < N - 1; i++) {
        int u, v, w; scanf("%d %d %d", &u, &v, &w);
        u--; v--;

        adj[u].push_back(pii(v, w));
        adj[v].push_back(pii(u, w));
    }

    dsu.init();
    ans = 0;
    cnt = 0;
    while(cnt < N - 1) solve();

    printf("%lld", ans);
}


Measured memory_bytes: 76084