#include <bits/stdc++.h>

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 200179;

struct DSU {
    int p[N];
    void init(int n) {
        memset(p, -1, sizeof(int)*n);
    }
    int get(int x) {
        return p[x] == -1 ? x : p[x] = get(p[x]);
    }
    bool merge(int x, int y) {
        x = get(x);
        y = get(y);
        if (x == y)
            return false;
        p[x] = y;
        return true;
    }
} dsu;

int n;
int x[N];
vector<ipair> e[N];
int col[N];
int cc;

int main() {
    ios::sync_with_stdio(false);

    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        scanf("%d", x + i);
    for (int i = 0; i < n - 1; ++i) {
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        --x;
        --y;
        e[x].push_back({y, z});
        e[y].push_back({x, z});
    }

    iota(col, col + n, 0);
    cc = n;
    ll ans = 0;
    while (cc > 1) {
        pair<ll, int> d[N];
        priority_queue<pair<pair<ll, int>, int>, vector<pair<pair<ll, int>, int>>, greater<pair<pair<ll, int>, int>>> q;
        for (int i = 0; i < n; ++i)
            q.push({d[i] = {x[i], col[i]}, i});
        while (!q.empty()) {
            int v = q.top().Y;
            auto cd = q.top().X;
            q.pop();
            if (cd != d[v])
                continue;
            for (ipair nvp : e[v]) {
                int nv = nvp.X;
                pair<ll,int> nd = {cd.X + nvp.Y, cd.Y};
                if (nd < d[nv]) {
                    q.push({d[nv] = nd, nv});
                }
            }
        }

        static int csb[N];
        static ll csbv[N];
        memset(csbv, 0x3f, sizeof(ll)*cc);
        auto upd = [&](int c, int c2, ll v) {
            if (c == c2)
                return;
            if (v < csbv[c]) {
                csbv[c] = v;
                csb[c] = c2;
            } else if (v == csbv[c])
                csb[c] = min(csb[c], c2);
            swap(c, c2);
            if (v < csbv[c]) {
                csbv[c] = v;
                csb[c] = c2;
            } else if (v == csbv[c])
                csb[c] = min(csb[c], c2);
        };
        for (int v1 = 0; v1 < n; ++v1) {
            upd(col[v1], d[v1].Y, d[v1].X + x[v1]);
            for (ipair v2p : e[v1])
                upd(d[v1].Y, d[v2p.X].Y, d[v1].X + d[v2p.X].X + v2p.Y);
        }

        dsu.init(cc);
        for (int i = 0; i < cc; ++i)
            if (dsu.merge(i, csb[i]))
                ans += csbv[i];
        static int c2c[N];
        memset(c2c, -1, sizeof(int)*cc);
        cc = 0;
        for (int i = 0; i < n; ++i) {
            int x = dsu.get(col[i]);
            if (c2c[x] == -1)
                c2c[x] = cc++;
            col[i] = c2c[x];
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 42396