///////////////////////// _LeMur_
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>
using namespace std;
const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 998244353;
int n;
int a[N];
vector < pair<int,int> > g[N];
bool used[N];
int order[N] , nn;
long long dp[N] , fin[N];
long long DP[N] , mn[N];
void rec(int v,int p){
++nn;
order[v] = 1;
dp[v] = fin[v] = 0;
DP[v] = mn[v] = 0;
for(int i=0;i<(int)g[v].size();i++){
int to = g[v][i].first;
if(to == p || used[to])continue;
rec(to , v);
order[v] += order[to];
}
}
int mnn , gag;
vector < long long > G;
void dfs(int v,int p){
int mx = nn - order[v];
for(int i=0;i<(int)g[v].size();i++){
int to = g[v][i].first;
int len = g[v][i].second;
if(to == p || used[to])continue;
dfs(to , v);
mx = max(mx , order[to]);
}
if(mx < mnn){
mnn = mx;
gag = v;
}
}
void made(int v,int p){
order[v] = 1;
for(int i=0;i<(int)g[v].size();i++){
int to = g[v][i].first;
int len = g[v][i].second;
if(to == p || used[to])continue;
///
fin[to] = fin[v] + a[v] - len;
dp[to] = dp[v];
if(fin[to] < 0){
dp[to] -= fin[to];
fin[to] = 0;
}
///
int delta = a[to] - len;
DP[to] = DP[v] + delta;
mn[to] = min(1ll * delta , mn[v] + delta);
///
made(to , v);
order[v] += order[to];
}
if(mn[v] >= 0){
G.push_back(DP[v]);
}
}
int findcenter(int v){
nn = 0;
rec(v , -1);
mnn = inf;
dfs(v , -1);
made(gag , -1);
return gag;
}
long long answ = 0;
map < long long,int > mp;
vector < long long > P;
vector <int> vert;
void solve(int v,int p){
if(p != -1){
vert.push_back(v);
if(mn[v] >= 0){
P.push_back(DP[v]);
}
}
int id = lower_bound(G.begin() , G.end() , dp[v]) - G.begin();
answ += (int)G.size() - id;
if(p == -1) answ--;
///
for(int i=0;i<(int)g[v].size();i++){
int to = g[v][i].first;
if(to == p || used[to])continue;
solve(to , v);
if(p == -1){
sort(P.begin() , P.end());
for(int j=0;j<(int)vert.size();j++){
int gag = vert[j];
int id = lower_bound(P.begin() , P.end() , dp[gag]) - P.begin();
answ -= (int)P.size() - id;
}
P.clear();
vert.clear();
}
}
}
void centroid(){
queue <int> q;
q.push(1);
while(!q.empty()){
int v = q.front();
q.pop();
v = findcenter(v);
///
sort(G.begin() , G.end());
solve(v , -1);
G.clear();
///
for(int i=0;i<(int)g[v].size();i++){
int to = g[v][i].first;
if(order[to] == 1 || used[to])continue;
q.push(to);
}
used[v] = true;
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<n;i++){
int a , b , c;
scanf("%d%d%d",&a,&b,&c);
g[a].push_back(make_pair(b , c));
g[b].push_back(make_pair(a , c));
}
centroid();
cout<<answ<<endl;
return 0;
}
Ly8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLyAgIF9MZU11cl8KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGNhc3NlcnQ+CiNpbmNsdWRlIDxiaXRzZXQ+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPGN0aW1lPgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHNldD4KIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmNvbnN0IGludCBOID0gMTAwMDA1Owpjb25zdCBpbnQgaW5mID0gMTAwMCAqIDEwMDAgKiAxMDAwOwpjb25zdCBpbnQgbW9kID0gOTk4MjQ0MzUzOwogCmludCBuOwppbnQgYVtOXTsKIAp2ZWN0b3IgPCBwYWlyPGludCxpbnQ+ID4gZ1tOXTsKYm9vbCB1c2VkW05dOwogCmludCBvcmRlcltOXSAsIG5uOwogCmxvbmcgbG9uZyBkcFtOXSAsIGZpbltOXTsKbG9uZyBsb25nIERQW05dICwgbW5bTl07CiAKdm9pZCByZWMoaW50IHYsaW50IHApewogICAgKytubjsKICAgIG9yZGVyW3ZdID0gMTsKICAgIGRwW3ZdID0gZmluW3ZdID0gMDsKICAgIERQW3ZdID0gbW5bdl0gPSAwOwogICAgZm9yKGludCBpPTA7aTwoaW50KWdbdl0uc2l6ZSgpO2krKyl7CiAgICAgICAgaW50IHRvID0gZ1t2XVtpXS5maXJzdDsKICAgICAgICBpZih0byA9PSBwIHx8IHVzZWRbdG9dKWNvbnRpbnVlOwogICAgICAgIHJlYyh0byAsIHYpOwogICAgICAgIG9yZGVyW3ZdICs9IG9yZGVyW3RvXTsKICAgIH0KfQogCmludCBtbm4gLCBnYWc7CiAKdmVjdG9yIDwgbG9uZyBsb25nID4gRzsKIAp2b2lkIGRmcyhpbnQgdixpbnQgcCl7CiAgICBpbnQgbXggPSBubiAtIG9yZGVyW3ZdOwogICAgZm9yKGludCBpPTA7aTwoaW50KWdbdl0uc2l6ZSgpO2krKyl7CiAgICAgICAgaW50IHRvID0gZ1t2XVtpXS5maXJzdDsKICAgICAgICBpbnQgbGVuID0gZ1t2XVtpXS5zZWNvbmQ7CiAgICAgICAgaWYodG8gPT0gcCB8fCB1c2VkW3RvXSljb250aW51ZTsKICAgICAgICBkZnModG8gLCB2KTsKICAgICAgICBteCA9IG1heChteCAsIG9yZGVyW3RvXSk7CiAgICB9CiAgICBpZihteCA8IG1ubil7CiAgICAgICAgbW5uID0gbXg7CiAgICAgICAgZ2FnID0gdjsKICAgIH0KfQogCnZvaWQgbWFkZShpbnQgdixpbnQgcCl7CiAgICBvcmRlclt2XSA9IDE7CiAgICBmb3IoaW50IGk9MDtpPChpbnQpZ1t2XS5zaXplKCk7aSsrKXsKICAgICAgICBpbnQgdG8gPSBnW3ZdW2ldLmZpcnN0OwogICAgICAgIGludCBsZW4gPSBnW3ZdW2ldLnNlY29uZDsKICAgICAgICBpZih0byA9PSBwIHx8IHVzZWRbdG9dKWNvbnRpbnVlOwogICAgICAgIC8vLwogICAgICAgIGZpblt0b10gPSBmaW5bdl0gKyBhW3ZdIC0gbGVuOwogICAgICAgIGRwW3RvXSA9IGRwW3ZdOwogICAgICAgIGlmKGZpblt0b10gPCAwKXsKICAgICAgICAgICAgZHBbdG9dIC09IGZpblt0b107CiAgICAgICAgICAgIGZpblt0b10gPSAwOwogICAgICAgIH0KICAgICAgICAvLy8KICAgICAgICBpbnQgZGVsdGEgPSBhW3RvXSAtIGxlbjsKICAgICAgICBEUFt0b10gPSBEUFt2XSArIGRlbHRhOwogICAgICAgIG1uW3RvXSA9IG1pbigxbGwgKiBkZWx0YSAsIG1uW3ZdICsgZGVsdGEpOwogICAgICAgIC8vLwogICAgICAgIG1hZGUodG8gLCB2KTsKICAgICAgICBvcmRlclt2XSArPSBvcmRlclt0b107CiAgICB9CiAgICBpZihtblt2XSA+PSAwKXsKICAgICAgICBHLnB1c2hfYmFjayhEUFt2XSk7CiAgICB9Cn0KIAppbnQgZmluZGNlbnRlcihpbnQgdil7CiAgICBubiA9IDA7CiAgICByZWModiAsIC0xKTsKICAgIG1ubiA9IGluZjsKICAgIGRmcyh2ICwgLTEpOwogICAgbWFkZShnYWcgLCAtMSk7CiAgICByZXR1cm4gZ2FnOwp9CiAKbG9uZyBsb25nIGFuc3cgPSAwOwptYXAgPCBsb25nIGxvbmcsaW50ID4gbXA7CiAKdmVjdG9yIDwgbG9uZyBsb25nID4gUDsKdmVjdG9yIDxpbnQ+IHZlcnQ7CiAKdm9pZCBzb2x2ZShpbnQgdixpbnQgcCl7CiAgICBpZihwICE9IC0xKXsKICAgICAgICB2ZXJ0LnB1c2hfYmFjayh2KTsKICAgICAgICBpZihtblt2XSA+PSAwKXsKICAgICAgICAgICAgUC5wdXNoX2JhY2soRFBbdl0pOwogICAgICAgIH0KICAgIH0KICAgIGludCBpZCA9IGxvd2VyX2JvdW5kKEcuYmVnaW4oKSAsIEcuZW5kKCkgLCBkcFt2XSkgLSBHLmJlZ2luKCk7CiAgICBhbnN3ICs9IChpbnQpRy5zaXplKCkgLSBpZDsKICAgIGlmKHAgPT0gLTEpIGFuc3ctLTsKICAgIC8vLwogICAgZm9yKGludCBpPTA7aTwoaW50KWdbdl0uc2l6ZSgpO2krKyl7CiAgICAgICAgaW50IHRvID0gZ1t2XVtpXS5maXJzdDsKICAgICAgICBpZih0byA9PSBwIHx8IHVzZWRbdG9dKWNvbnRpbnVlOwogICAgICAgIHNvbHZlKHRvICwgdik7CiAgICAgICAgaWYocCA9PSAtMSl7CiAgICAgICAgICAgIHNvcnQoUC5iZWdpbigpICwgUC5lbmQoKSk7CiAgICAgICAgICAgIGZvcihpbnQgaj0wO2o8KGludCl2ZXJ0LnNpemUoKTtqKyspewogICAgICAgICAgICAgICAgaW50IGdhZyA9IHZlcnRbal07CiAgICAgICAgICAgICAgICBpbnQgaWQgPSBsb3dlcl9ib3VuZChQLmJlZ2luKCkgLCBQLmVuZCgpICwgZHBbZ2FnXSkgLSBQLmJlZ2luKCk7CiAgICAgICAgICAgICAgICBhbnN3IC09IChpbnQpUC5zaXplKCkgLSBpZDsKICAgICAgICAgICAgfQogICAgICAgICAgICBQLmNsZWFyKCk7CiAgICAgICAgICAgIHZlcnQuY2xlYXIoKTsKICAgICAgICB9CiAgICB9Cn0KIAp2b2lkIGNlbnRyb2lkKCl7CiAgICBxdWV1ZSA8aW50PiBxOwogICAgcS5wdXNoKDEpOwogICAgd2hpbGUoIXEuZW1wdHkoKSl7CiAgICAgICAgaW50IHYgPSBxLmZyb250KCk7CiAgICAgICAgcS5wb3AoKTsKICAgICAgICB2ID0gZmluZGNlbnRlcih2KTsKICAgICAgICAvLy8KICAgICAgICBzb3J0KEcuYmVnaW4oKSAsIEcuZW5kKCkpOwogICAgICAgIHNvbHZlKHYgLCAtMSk7CiAgICAgICAgRy5jbGVhcigpOwogICAgICAgIC8vLwogICAgICAgIGZvcihpbnQgaT0wO2k8KGludClnW3ZdLnNpemUoKTtpKyspewogICAgICAgICAgICBpbnQgdG8gPSBnW3ZdW2ldLmZpcnN0OwogICAgICAgICAgICBpZihvcmRlclt0b10gPT0gMSB8fCB1c2VkW3RvXSljb250aW51ZTsKICAgICAgICAgICAgcS5wdXNoKHRvKTsKICAgICAgICB9CiAgICAgICAgdXNlZFt2XSA9IHRydWU7CiAgICB9Cn0KIAppbnQgbWFpbigpewogICAgc2NhbmYoIiVkIiwmbik7CiAgICBmb3IoaW50IGk9MTtpPD1uO2krKyl7CiAgICAgICAgc2NhbmYoIiVkIiwmYVtpXSk7CiAgICB9CiAgICBmb3IoaW50IGk9MTtpPG47aSsrKXsKICAgICAgICBpbnQgYSAsIGIgLCBjOwogICAgICAgIHNjYW5mKCIlZCVkJWQiLCZhLCZiLCZjKTsKICAgICAgICBnW2FdLnB1c2hfYmFjayhtYWtlX3BhaXIoYiAsIGMpKTsKICAgICAgICBnW2JdLnB1c2hfYmFjayhtYWtlX3BhaXIoYSAsIGMpKTsKICAgIH0KICAgIGNlbnRyb2lkKCk7CiAgICBjb3V0PDxhbnN3PDxlbmRsOwogICAgcmV0dXJuIDA7Cn0=