Language: C++

#include<stdio.h>
#include<algorithm>
using namespace std;
int fa[131072],rank[131072],fw[131072];
int findroot(int x)
{
	if(fa[x]==x)
	{
		return x;
	}
	return findroot(fa[x]);
}
int chk(int u,int v)
{
	int ans=0;
	while(u!=v)
	{
		if(fw[u]<fw[v])
		{
			if(fw[u]>ans)
			{
				ans=fw[u];
			}
			u=fa[u];
		}
		else
		{
			if(fw[v]>ans)
			{
				ans=fw[v];
			}
			v=fa[v];
		}
	}
	return ans;
}
struct node{
	int u;
	int v;
	int w;
	bool operator<(node b) const
	{
		return w<b.w;
	}
};
node nn[262144];
int main()
{
	int n,m;
	long long x;
	scanf("%d%d%lld",&n,&m,&x);
	for(int i=1;i<=n;i++)
	{
		fa[i]=i;
		rank[i]=1;
		fw[i]=1000000007;
	}
	for(int i=0;i<m;i++)
	{
		scanf("%d%d%d",&nn[i].u,&nn[i].v,&nn[i].w);
	}
	if(n<=2)
	{
		printf("0\n");
		return 0;
	}
	sort(nn,nn+m);
	long long s=0;
	int num=0;
	for(int i=0;i<m;i++)
	{
		int u=findroot(nn[i].u);
		int v=findroot(nn[i].v);
		if(u==v)
		{
			continue;
		}
		s+=nn[i].w;
		num++;
		if(rank[u]>rank[v])
		{
			fa[v]=u;
			fw[v]=nn[i].w;
		}
		else
		{
			if(rank[u]==rank[v])
			{
				rank[v]++;
			}
			fa[u]=v;
			fw[u]=nn[i].w;
		}
	}
	if(num<n-1)
	{
		printf("0\n");
		return 0;
	}
	if(s>x)
	{
		printf("0\n");
		return 0;
	}
	int ss=2,ss2=2;
	if(s==x)
	{
		ss=1;
	}
	for(int i=0;i<m;i++)
	{
		int d=nn[i].w-chk(nn[i].u,nn[i].v);
		if(s+d>=x)
		{
			ss<<=1;
			if(ss>=1000000007)
			{
				ss-=1000000007;
			}
		}
		if(s+d>x)
		{
			ss2<<=1;
			if(ss2>=1000000007)
			{
				ss2-=1000000007;
			}
		}
	}
	ss-=ss2;
	if(ss<0)
	{
		ss+=1000000007;
	}
	printf("%d\n",ss);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:17: error: reference to 'rank' is ambiguous
   55 |                 rank[i]=1;
      |                 ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:2:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:4:16: note:                 'int rank [131072]'
    4 | int fa[131072],rank[131072],fw[131072];
      |                ^~~~
a.cc:80:20: error: reference to 'rank' is ambiguous
   80 |                 if(rank[u]>rank[v])
      |                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:4:16: note:                 'int rank [131072]'
    4 | int fa[131072],rank[131072],fw[131072];
      |                ^~~~
a.cc:80:28: error: reference to 'rank' is ambiguous
   80 |                 if(rank[u]>rank[v])
      |                            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:4:16: note:                 'int rank [131072]'
    4 | int fa[131072],rank[131072],fw[131072];
      |                ^~~~
a.cc:87:28: error: reference to 'rank' is ambiguous
   87 |                         if(rank[u]==rank[v])
      |                            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:4:16: note:                 'int rank [131072]'
    4 | int fa[131072],rank[131072],fw[131072];
      |                ^~~~
a.cc:87:37: error: reference to 'rank' is ambiguous
   87 |                         if(rank[u]==rank[v])
      |                                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:4:16: note:                 'int rank [131072]'
    4 | int fa[131072],rank[131072],fw[131072];
      |                ^~~~
a.cc:89:33: error: reference to 'rank' is ambiguous
   89 |                                 rank[v]++;
      |                                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:4:16: note:                 'int rank [131072]'
    4 | int fa[131072],rank[131072],fw[131072];
      |                ^~~~