import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long INF = 1L<<59;

void main() {
    auto N = readln.chomp.to!int;
    auto X = readln.split.map!(to!long).array;
    auto G = new Tuple!(int, long)[][](2*N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, s[2].to!long);
        G[s[1]-1] ~= tuple(s[0]-1, s[2].to!long);
    }
    foreach (i; 0..N) {
        G[i] ~= tuple(i+N, X[i]);
        G[i+N] ~= tuple(i, X[i]);
    }

    auto dist = new long[](2*N);
    auto color = new int[](2*N);
    auto pq = new BinaryHeap!(Array!(Tuple!(int, int, long)), "a[2] > b[2]");
    foreach (i; N..2*N) pq.insert(tuple(i, i, 0L));
    dist[] = 1L << 59;


    while (!pq.empty) {
        auto n = pq.front[0];
        auto c = pq.front[1];
        auto d = pq.front[2];
        pq.removeFront;
        if (dist[n] <= d) continue;
        dist[n] = d;
        color[n] = c;
        foreach (e; G[n]) {
            auto m = e[0];
            auto nd = d + e[1];
            if (dist[m] <= nd) continue;
            pq.insert(tuple(m, c, nd));
        }
    }


    long ans = 0;

    foreach (i; 0..2*N) {
        foreach (e; G[i]) {
            int j = e[0];
            long c = e[1];
            if (j > i || color[i] == color[j]) continue;
            ans += dist[i] + dist[j] + c;
        }
    }

    ans.writeln;
}
