#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pair;
typedef pair<ll, int> Pairll;

const int Nmax = 2e5 + 5;

int n, All;
int X[Nmax];
int color[Nmax], to[Nmax], new_color[Nmax];
ll dist[Nmax], closest[Nmax];

vector<int> centroids;

Pairll r[Nmax];

bool used[Nmax], bad[Nmax];
int w[Nmax];

vector<int> v[Nmax];
vector<Pair> c[Nmax];
vector<int> edge[Nmax];

vector<int> z;
ll mp[Nmax];



static void dfs(int node, int Id)
{
    used[node] = 1;
    new_color[node] = Id;

    for(auto it : edge[node])
        if(!used[it])
            dfs(it, Id);
}


static void dfs0(int node, int dad = 0)
{
    w[node] = 1;
    for(auto it : v[node])
        if(it != dad && !bad[it])
        {
            dfs0(it, node);
            w[node] += w[it];
        }
}

static Pair centroid(int node, int dad = 0)
{
    Pair best = {n, n};
    int worst = All - w[node];

    for(auto it : v[node])
        if(it != dad && !bad[it])
        {
            best = min(best, centroid(it, node));
            worst = max(worst, w[it]);
        }
    return min(best, {worst, node});
}

static void combine(int x, ll y)
{
    if(mp[x] == 0)
    {
        mp[x] = y;
        z.push_back(x);
    }
    else if(mp[x] > y) mp[x] = y;
}

static void dfs1(int node, int dad = 0)
{
    combine(color[node], dist[node] + X[node]);

    for(auto it : c[node])
        if(it.first != dad && !bad[it.first])
        {
            dist[it.first] = dist[node] + it.second;
            dfs1(it.first, node);
        }
}

void find_edges_now()
{
    Pairll best = {1e18+1, -1};

    for(auto it = z.begin(); it != z.end(); ++it)
    {
        r[*it] = min(r[*it], make_pair(best.first + mp[*it], best.second) );
        best = min(best, make_pair(mp[*it], *it));
    }

    best = {1e18+1, -1};

    for(auto it = z.rbegin(); it != z.rend(); ++it)
    {
        r[*it] = min(r[*it], make_pair(best.first + mp[*it], best.second) );
        best = min(best, make_pair(mp[*it], *it));
    }
}

void solve0(int node)
{
    dist[node] = 0;
    dfs1(node);

    find_edges_now();

    bad[node] = 1;

    for(auto it : z) mp[it] = 0;
    z.clear();
}

void find_centroids(int node)
{
    dfs0(node);
    All = w[node];
    node = centroid(node).second;

    centroids.push_back(node);
    bad[node] = 1;

    for(auto it : v[node])
        if(!bad[it])
            find_centroids(it);
}

void find_edges(int C)
{
    memset(bad, 0, sizeof(bad));
    int i;
    for(i=1; i<=C; ++i) r[i] = {1e18, -1};

    for(auto node : centroids) solve0(node);

    for(i=1; i<=C; ++i)
        to[i] = r[i].second, closest[i] = r[i].first;
}

ll solve(int &C)
{
    find_edges(C);

    memset(used, 0, sizeof(used));

    ll ans = 0;
    int i;
    for(i=1; i<=C; ++i) edge[i].clear();

    for(i=1; i<=C; ++i)
        if(to[to[i]] != i || i < to[i])
        {
            edge[i].push_back(to[i]);
            edge[to[i]].push_back(i);

            ans += closest[i];
        }

    int Id = 0;

    for(i=1; i<=C; ++i)
        if(!used[i])
            ++Id, dfs(i, Id);

    for(i=1; i<=n; ++i)
        color[i] = new_color[color[i]];

    C = Id;
    return ans;
}

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> n;

    int i;
    for(i=1; i<=n; ++i) cin >> X[i], color[i] = i;

    for(i=1; i<n; ++i)
    {
        int x, y, cost;
        cin >> x >> y >> cost;
        v[x].push_back(y);
        v[y].push_back(x);
        c[x].push_back({y, cost});
        c[y].push_back({x, cost});
    }

    find_centroids(1);

    ll ans = 0;
    int C = n;

    while(C > 1)
        ans += solve(C);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 69748