#include<bits/stdc++.h>
using namespace std;
struct Node{
int c;
queue <int> l,lenl;
long long zs;
bool bj;
}s[100001];
void dfs(int i,int len,int z)
{
s[i].bj=1;
if(i==0)
return;
s[i].zs+=s[z].c*len;
queue <int> y1,y2;
while(!s[i].l.empty()){
if(!s[s[i].l.front()].bj)
dfs(s[i].l.front(),len+s[i].lenl.front(),z);
y1.push(s[i].l.front());
y2.push(s[i].lenl.front());
s[i].l.pop();
s[i].lenl.pop();
}
while(!y1.empty()){
s[i].l.push(y1.front());
s[i].lenl.push(y2.front());
y1.pop();
y2.pop();
}
}
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&s[i].c);
for(int i=1;i<n;i++){
int x1,x2,len;
scanf("%d%d%d",&x1,&x2,&len);
s[x1].l.push(x2);
s[x1].lenl.push(len);
s[x2].l.push(x1);
s[x2].lenl.push(len);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
s[j].bj=0;
dfs(i,0,i);
}
long long js=99999999;
for(int i=1;i<=n;i++)
js=min(s[i].zs,js);
cout<<js;
return 0;
}