Failing all the test cases,but the given test case pass

#include <bits/stdc++.h>
using namespace std;
class DSU
{
int *parent;
int *rank;
public:
DSU(int v)
{
parent=new int[v];
rank=new int[v];

    for(int i=0;i<v;i++)
    {
        parent[i]=-1;
        rank[i]=1;
    }
}
int find(int i)
{
    if(parent[i]==-1)
    {
        return i;
    }

    return parent[i]=find(parent[i]);
}

void union_set(int x,int y)
{
    int S1=find(x);
    int S2=find(y);

    if(S1!=S2)
    {
        if(rank[S1]<rank[S2])
        {
            parent[S1]=S2;
            rank[S2]+=rank[S1];
        }
        else
        {
            parent[S2]=S1;
            rank[S1]+=rank[S2];
        }
    }
}

};
class Graph
{
int v;
vector<vector > edgeList;
public:
Graph(int V)
{
v=V;
}
void addEdge(int x,int y,int w)
{
edgeList.push_back({w,x,y});
}
void kruskal(long long s)
{
DSU d(v);
sort(edgeList.begin(),edgeList.end(),greater<vector >());
long long ans=0;
long long cnt=0;
vector remaining;
for(auto edge:edgeList)
{
int w=edge[0];
int x=edge[1];
int y=edge[2];

        if(d.find(x)!=d.find(y))
        {
            d.union_set(x,y);
            
        }
		else
		{
			remaining.push_back(w);
		}
    }
	sort(remaining.begin(),remaining.end());
	for(int x:remaining)
	{
		if((x+ans)<=s)
		{
			cnt++;
			ans+=x;
		}
	}
    cout<<cnt<<" "<<ans<<endl;
}

};
int main() {
/* code here */
int v,e;
long long s;
cin>>v>>e>>s;
Graph G(v);
int x,y,z;
for(int i=0;i<e;i++)
{
cin>>x>>y>>z;
G.addEdge(x,y,z);
}
G.kruskal(s);

return 0;

}