#include <algorithm>
#include <cstdio>
#include <utility>
#include <vector>

const int N = 200000;

using VPII = std::vector<std::pair<long long, int>>;

int weight[N], color[N];
std::pair<long long, int> best[N];
std::vector<int> order;
VPII tree[N], son[N], down[N], up[N];

int find(int u)
{
    if (color[u] != u) {
        color[u] = find(color[u]);
    }
    return color[u];
}

void prepare(int p, int u)
{
    order.push_back(u);
    for (auto it : tree[u]) {
        if (it.first != p) {
            son[u].push_back(it);
            prepare(u, it.first);
        }
    }
}

void add(VPII& p, long long v, int c)
{
    for (auto& it : p) {
        if (it.second == c) {
            if (v < it.first) {
                it.first = v;
            }
            std::sort(p.begin(), p.end());
            return;
        }
    }
    p.emplace_back(v, c);
    std::sort(p.begin(), p.end());
    if (p.size() > 2) {
        p.resize(2);
    }
}

void add(VPII& p, const VPII& q, int l)
{
    for (auto elem : q) {
        add(p, elem.first + l, elem.second);
    }
}

int main()
{
#ifdef LOCAL_JUDGE
    freopen("J.in", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) {
        scanf("%d", weight + i);
        color[i] = i;
    }
    for (int i = 1, a, b, c; i < n; ++ i) {
        scanf("%d%d%d", &a, &b, &c);
        a --;
        b --;
        tree[a].emplace_back(b, c);
        tree[b].emplace_back(a, c);
    }
    prepare(-1, 0);
    int comp = n;
    long long result = 0;
    while (comp > 1) {
        for (int i = n - 1; i >= 0; -- i) {
            int u = order[i];
            up[u] = down[u] = { {weight[u], find(u)} };
            for (auto it : son[u]) {
                add(down[u], down[it.first], it.second);
            }
        }
        for (int i = 0; i < n; ++ i) {
            int u = order[i];
            auto tmp = up[u];
            for (int j = 0; j < (int)son[u].size(); ++ j) {
                auto v = son[u][j].first;
                auto l = son[u][j].second;
                add(up[v], tmp, l);
                add(tmp, down[son[u][j].first], l);
            }
            tmp.clear();
            for (int j = (int)son[u].size() - 1; j >= 0; -- j) {
                auto v = son[u][j].first;
                auto l = son[u][j].second;
                add(up[v], tmp, l);
                add(tmp, down[son[u][j].first], l);
            }
        }
        for (int u = 0; u < n; ++ u) {
            best[u] = {1000000000000000000LL, -1};
        }
        for (int u = 0; u < n; ++ u) {
            int c = find(u);
            for (auto elem : up[u]) {
                if (elem.second != c) {
                    best[c] = std::min(best[c], std::make_pair(weight[u] + elem.first, elem.second));
                }
            }
            for (auto elem : down[u]) {
                if (elem.second != c) {
                    best[c] = std::min(best[c], std::make_pair(weight[u] + elem.first, elem.second));
                }
            }
        }
        for (int u = 0; u < n; ++ u) {
            if (~best[u].second && find(u) != find(best[u].second)) {
                comp --;
                result += best[u].first;
                color[find(u)] = find(best[u].second);
            }
        }
    }
    printf("%lld\n", result);
}

Measured memory_bytes: 99956