#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200005
#define ll long long
#define int long long
using namespace std;
struct edge
{
	int u, v;
	edge *next;
}egp[maxn << 1], *h[maxn];
int egcnt = 0;
void addedge(int u, int v)
{
	edge *n1 = &egp[egcnt++];
	n1->u = u, n1->v = v, n1->next = h[u], h[u] = n1;
}
int dfn[maxn], pre[maxn], dep[maxn], size[maxn], son[maxn], top[maxn];
int tr[maxn];
int num[maxn];
ll sum[maxn];
int dfcnt = 0;
void dfs1(int a)
{
	size[a] = 1;
	sum[a] = num[a];
//	cout<<"PRE"<<a<<" "<<pre[a]<<endl;
	for(edge *p = h[a]; p; p = p->next)
	{
		if(p->v == pre[a]) continue;
		dep[p->v] = dep[a] + 1, 
		pre[p->v] = a;
		dfs1(p->v);
		sum[a] += sum[p->v];
		size[a] += size[p->v];
		if(size[p->v] > size[son[a]])
			son[a] = p->v; 
	}
}
void dfs2(int a)
{
	dfn[a] = ++dfcnt;
	if(son[a])
		top[son[a]] = top[a], 
		dfs2(son[a]);
	for(edge *p = h[a]; p; p = p->next)
	{
		if(p->v == pre[a] || p->v == son[a]) continue;
		top[p->v] = p->v, dfs2(p->v);
	}
}
struct ST
{
	ST *ch[2];
	ll lz;
	int l, r, mxs;
}stp[maxn << 2], *root;
int stcnt = 0;
void bdtree(ST *a, int l, int r)
{
	a->l = l, a->r = r, a->mxs = -1, a->lz = 0;
	if(l == r) return;
	int mid = (l + r) >> 1;
	a->ch[0] = &stp[stcnt++], a->ch[1] = &stp[stcnt++];
	bdtree(a->ch[0], l, mid), 
	bdtree(a->ch[1], mid + 1, r);
}
void ins(ST *a, int pl)
{
	a->mxs = max(a->mxs, pl);
	if(a->l == a->r) return;
	int mid = (a->l + a->r) >> 1;
	if(pl <= mid) ins(a->ch[0], pl);
	else ins(a->ch[1], pl);
}
void push(ST *a, int l, int r, ll s)
{
	if(a->l == l && a->r == r)
	{
		a->lz += s;
		return;
	}
	int mid = (a->l + a->r) >> 1;
	if(r <= mid) push(a->ch[0], l, r, s);
	else if(l > mid) push(a->ch[1], l, r, s);
	else push(a->ch[0], l, mid, s),
		push(a->ch[1], mid + 1, r, s);
}
int qmx(ST *a, int l, int r)
{
	if(a->l == l && a->r == r)
		return a->mxs;
	int mid = (a->l + a->r) >> 1;
	if(r <= mid) return qmx(a->ch[0], l, r);
	else if(l > mid) return qmx(a->ch[1], l, r);
	else 
		return 
		max(qmx(a->ch[0], l, mid),
		qmx(a->ch[1], mid + 1, r));
}
ll qsum(ST *a, int pl)
{
	if(a->l == a->r) 
		return a->lz;
	int mid = (a->l + a->r) >> 1;
	if(pl <= mid) return a->lz + qsum(a->ch[0], pl);
	else return a->lz + qsum(a->ch[1], pl);
}
int gf(int x)
{
	while(x)
	{
		int ns = qmx(root, dfn[top[x]], dfn[x]);
	//	cout<<"QQ"<<x<<" "<<ns<<endl;
		if(ns != -1) return tr[ns];
		x = pre[top[x]];
	}
	while(1);
}

ll q(int pl)
{
	int rf = gf(pl);
//	cout<<"QUERY"<<pl<<" "<<rf<<" "<<sum[rf]<<" "<<qsum(root, dfn[rf])<<endl;
	return sum[rf] - qsum(root, dfn[rf]);
}
void cut(int u, int v)
{
	if(pre[v] == u) swap(u, v);
	if(pre[u] != v) while(1);
	ll n1 = sum[u] - qsum(root, dfn[u]);
	int rf = gf(u);
	ins(root, dfn[u]);
//	cout<<"INS"<<u<<" "<<n1<<endl;
	u = pre[u];
	while(dep[u] >= dep[rf])
	{
		if(dep[top[u]] >= dep[rf])
			push(root, dfn[top[u]], dfn[u], n1), 
			u = pre[top[u]];
		else
		{
			if(top[rf] != top[u]) while(1);
			push(root, dfn[rf], dfn[u], n1), 
			u = pre[rf];
		}
	}
}
int fa[maxn];
int gfa(int a)
{
	if(fa[a] == a) return a;
	return fa[a] = gfa(fa[a]);
}
struct eg
{
	int u, v, w, fl;
	bool operator < (const eg &x)const
	{
		return w < x.w;
	}
}p[maxn];
#undef int 
int main()
{
	#define int long long
	int n, m;
	scanf("%lld%lld", &n, &m);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &num[i]), 
		fa[i] = i;
	for(int i = 1; i <= m; i++)
		scanf("%lld%lld%lld", &p[i].u, &p[i].v, &p[i].w);
	sort(p + 1, p + m + 1);
	for(int i = 1; i <= m; i++)
	{
		int ufa = gfa(p[i].u), vfa = gfa(p[i].v);
		if(ufa == vfa) p[i].fl = 0;
		else 
			p[i].fl = 1, 
			fa[ufa] = vfa, 
			addedge(p[i].u, p[i].v), 
			addedge(p[i].v, p[i].u);
	}
	dep[1] = 1, top[1] = 1;
	dfs1(1), dfs2(1);
	for(int i = 1; i <= n; i++)
		tr[dfn[i]] = i;
	root = &stp[stcnt++];
	bdtree(root, 1, n);
	ins(root, 1);
	int cnt = 0;
	for(int i = m; i >= 1; i--)
	{
		ll ns = q(p[i].u);
		ll n2 = q(p[i].v);
	//	cout<<ns<<" "<<n2<<" "<<p[i].u<<" "<<p[i].v<<endl;
		if(ns != n2) while(1);
	//	cout<<i<<" "<<ns<<endl;
		if(ns >= p[i].w) continue;
		else
		{
			cnt++;
			if(p[i].fl)
			{
				cut(p[i].u, p[i].v);
			}
		}
	}
	printf("%d\n", cnt);
	return 0;
} 

Measured memory_bytes: 41984