#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll find(ll a[],ll x)
{
if(a[x]==x)
return x;
return a[x]=find(a,a[x]);
}
void unite(ll a[],ll x,ll z)
{
x=find(a,x);
z=find(a,z);
if(x!=z)
a[x]=z;
}
int main() {
ll n,m,total;
cin>>n>>m>>total;
vector<vector>v(m);
ll i;
for(i=0;i<m;i++)
{
int x,y,w;
cin>>x>>y>>w;
v[i]={w,x,y};
}
ll a[n+5];
for(i=1;i<=n;i++)
a[i]=i;
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
ll s=0;
vectore;
for(i=0;i<m;i++)
{
int x=v[i][1];
int y=v[i][2];
int w=v[i][0];
if(find(a,x)!=find(a,y))
{
unite(a,x,y);
s+=w;
}
else
e.push_back(w);
}
ll d=0,d1=0;
sort(e.begin(),e.end());
for(i=0;i<e.size();i++)
{
if((total-e[i])<0)
break;
total-=e[i];
d++;
d1+=e[i];
}
cout<<d<<" “<<d1<<”\n";
return 0;
}
sir i dont find out where my code gets stuck because it give wrong ans in one test case
Regarding testcase fail
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.