Language: C++

#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
辺を切り離した時の頂点の総和を高速に計算できないといけない
*/

struct D{
	ll a,b,c,id;
};
bool operator<(const D &lhs, const D &rhs){//全順序を定めないと，{1,0,0}=={1,1,0}
	if(lhs.c < rhs.c){
		return true;
	}else if(lhs.c == rhs.c){
		if(lhs.id < rhs.id){
			return true;
		}
	}
	return false;
}

ll n,m,ans=0,use[100010]={},y[100010];
vector<int> x(100010),v[100010],id[100010];
vector<D> cand;
D edge[100010];

struct UnionFind{
	int n;
	vector<ll> sum,r,p;
	UnionFind(){}
	UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);sum=x;}
	int find(int x){
		return (x==p[x]?x:p[x]=find(p[x]));
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y) return;
		if(r[x]<r[y]) swap(x,y);
		r[x]+=r[y];
		sum[x]+=sum[y];
		p[y]=x;
	}
	ll energy(int x){
		return sum[find(x)];
	}
};

int main(void){
	cin>>n>>m;
	reg(i,1,n)cin>>x[i];
	reg(i,1,m){
		ll a,b,c;
		cin>>a>>b>>c;
		edge[i]={a,b,c,i};
		v[a].push_back(b);
		v[b].push_back(a);
		id[a].push_back(i);
		id[b].push_back(i);
		y[i]=c;
	}
	//
	sort(edge+1,edge+1+m);
	UnionFind f(n+1);
	//
	reg(i,1,m){
		f.unite(edge[i].a,edge[i].b);
		ll sum = f.energy(edge[i].a);
		if(sum>=edge[i].c)cand.push_back(edge[i]);
		// cout<<sum<<endl;
		// printf("%lld,%lld,%lld\n",edge[i].a,edge[i].b,edge[i].c);
	}
	irep(i,cand.size()){
		if(use[cand[i].id]==0){
			//y[cand[i]]以下の辿れる辺全部使う
			queue<ll> Q;
			Q.push(cand[i].a);
			Q.push(cand[i].b);
			use[cand[i].id]=1;
			while(!Q.empty()){
				ll p = Q.front();Q.pop();
				rep(j,v[p].size()){
					if(use[id[p][j]]==0 && y[id[p][j]]<=y[cand[i].id]){
						use[id[p][j]]=1;
						Q.push(v[p][j]);
					}
				}
			}
		}
	}
	reg(i,1,m)if(use[i]==0)ans++;
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In constructor 'UnionFind::UnionFind(int)':
a.cc:50:79: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and 'std::vector<int>')
   50 |         UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);sum=x;}
      |                                                                               ^
In file included from /usr/include/c++/14/vector:72,
                 from a.cc:3:
/usr/include/c++/14/bits/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::vector<long long int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<long long int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::initializer_list<long long int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~