#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const LL oo=1e18;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int n; LL a[N];
#define pb push_back
struct EDGE { int v; LL w; };
vector <EDGE> G[N];
void add (int u,int v,int w) { G[u].pb ((EDGE){v,w}); }
struct UNION
{
    int fa[N],siz;
    void init () { for (int i=1; i<=n; i++) fa[i]=i; siz=n; }
    int getf (int x) { return fa[x]==x?x:fa[x]=getf (fa[x]); }
    bool merge (int x,int y)
    {
        x=getf (x),y=getf (y);
        if (x!=y) return fa[x]=y,--siz,1;
        return 0;
    }
}U;
struct LY { LL w; int c; }b[N][2];
void update (LY *a,LY x)
{
    if (x.w==oo) return ;
    if (a[1].c==x.c)
    {
        if (x.w< a[1].w) a[1]=x;
    }
    else if (a[0].c==x.c)
    {
        if (x.w< a[0].w) a[0]=x;
    }
    else if (x.w< a[1].w) a[1]=x;
    if (a[1].w< a[0].w) swap (a[0],a[1]);
}
void dfs0 (int u,int fa)
{
    b[u][0]=b[u][1]=(LY){oo,0};
    for (EDGE x:G[u])
    {
        int v=x.v; LL w=x.w;
        if (v==fa) continue;
        dfs0 (v,u);
        for (int j=0; j<=1; j++)
            update (b[u],(LY){b[v][j].w+w+a[u]-a[v],b[v][j].c});
        update (b[u],(LY){a[v]+w+a[u],U.getf (v)});
    }
}
LY pre[N][2],suf[N][2];
LY mi[N][2];
void dfs1 (int u,int fa)
{
	if (u==91)
	{
		++u;--u;
	}
    for (int j=0; j<=1; j++)
        pre[0][j]=suf[G[u].size ()][j]=mi[u][j];
    for (int i=0; i< (int)G[u].size (); i++)
    {
        EDGE x=G[u][i]; int v=x.v; LL w=x.w;
		if (i) memcpy (pre[i],pre[i-1],sizeof (pre[i]));//先memcpy再continue,否则会断开
        if (v==fa) continue;
        for (int j=0; j<=1; j++)
            update (pre[i],(LY){b[v][j].w+w-a[v],b[v][j].c});
        update (pre[i],(LY){a[v]+w,U.getf (v)});
    }
    for (int i=(int)G[u].size ()-1; i>=0; i--)
    {
        EDGE x=G[u][i]; int v=x.v; LL w=x.w;
		memcpy (suf[i],suf[i+1],sizeof (suf[i]));
        if (v==fa) continue;
        for (int j=0; j<=1; j++)
            update (suf[i],(LY){b[v][j].w+w-a[v],b[v][j].c});
        update (suf[i],(LY){a[v]+w,U.getf (v)});
    }
    for (int i=0; i< (int)G[u].size (); i++)
    {
        EDGE x=G[u][i]; int v=x.v; LL w=x.w;
        if (v==fa) continue;
        mi[v][0]=mi[v][1]=mi[1][0];
        update (mi[v],(LY){a[u]+w+a[v],U.getf (u)});
        for (int j=0; j<=1; j++)
            update (mi[v],(LY){mi[u][j].w+w+a[v]-a[u],mi[u][j].c});
        if (i) for (int j=0; j<=1; j++)
            update (mi[v],(LY){pre[i-1][j].w+w+a[v],pre[i-1][j].c});
        for (int j=0; j<=1; j++)
            update (mi[v],(LY){suf[i+1][j].w+w+a[v],suf[i+1][j].c});
    }
    for (EDGE x:G[u])
    {
        int v=x.v;
        if (v==fa) continue;
        dfs1 (v,u);
    }
}
int c[N];
LY x[N][2];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
    sc(n);
    for (int i=1; i<=n; i++)
        sc(a[i]);
    for (int i=1; i< n; i++)
    {
        int x,y,w; sc(x),sc(y),sc(w);
        add (x,y,w),add (y,x,w);
    }
    U.init ();
    mi[1][0]=mi[1][1]=(LY){oo,0};
    for (int i=1; i<=n; i++)
        x[i][0]=x[i][1]=mi[1][0];
    LL ans=0;
    while (U.siz> 1)
    {
        dfs0 (1,0);
        dfs1 (1,0);
        for (int i=1; i<=n; i++) c[i]=U.getf (i);
        for (int i=1; i<=n; i++)
        {
            for (int j=0; j<=1; j++)
                update (x[c[i]],b[i][j]),update (x[c[i]],mi[i][j]);
        }
        for (int i=1; i<=n; i++) if (c[i]==i)
        {
            if (x[i][0].c!=c[i]) ans+=U.merge (x[i][0].c,c[i])*x[i][0].w;
            else ans+=U.merge (x[i][1].c,c[i])*x[i][1].w;
            x[i][0]=x[i][1]=mi[1][0];
        }
    }
    pr(ans);

    return 0;
}


Measured memory_bytes: 120960