#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
ll n;
ll m;
const ll N = 1e5 + 10;
ll p[N];
ll sz[N];
ll ans[N];
ll fs(ll x)
{
        return p[x]==x ? x : p[x] = fs(p[x]);
}
bool ms(ll x, ll y)
{
        x = fs(x);
        y = fs(y);
        if(x==y) return false;
        sz[x] += sz[y]; sz[y]=0;
        ans[x] += ans[y]; ans[y]=0;
        p[y] = x;
        return true;
}
vector< tuple<ll,ll,ll> > e;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n >> m;
        for(ll i=1;i<=n;i++) {
                cin >> sz[i];
                p[i]=i;
        }
        for(ll i=1;i<=m;i++) {
                ll u,v,w;
                cin >> u >> v >> w;
                e.pb(make_tuple(w,u,v));
        }
        sort(e.begin(), e.end());
        for(auto i : e) {
                ll u,v,w;
                tie(w,u,v) = i;
                //cout << u << " " << v << " " << w << endl;
                if(ms(u,v) == false) {
                        if(w > sz[fs(u)]) {
                                ans[fs(u)]++;
                        }
                }else {
                        if(w <= sz[fs(u)]) ans[fs(u)] = 0;
                        else ans[fs(u)]++;
                }
        }
        for(ll i=1;i<=n;i++) {
                if(p[i] == i) {
                        cout << ans[i] << "\n";
                }
        }
        return 0;
}
