this code works well for the given test cases but results in “wrong answer” when i try to submit it on codechef…i am really finding it difficult to find the error hence need help…
#include<bits/stdc++.h>
#define MAXSIZE 10000
#define pb push_back
using namespace::std;
int dfs(vector< vector < int> > &g, int v, vector <bool> &vs)
{
vs[v] = true;
int count = 1;
for(auto it = g[v].begin() ; it != g[v].end() ; ++it)//auto it : g[v])
if(!vs[*it])
count += dfs(g,*it,vs);
return count;
}
void firesc(vector <vector <int> > &g, int n, vector <int> &result)
{
/*bool vs[n+1];
vs[0] = true;
for(int i =1 ; i <= n ; ++i)
vs[i] = false;*/
vector <bool> vs(n+1,false);
vs[0] = true;
for(int i = 0 ; i <= n ; ++i)
if(!vs[i])
result.pb(dfs(g,i,vs));
}
int main()
{ //0 1 2 3 4
int T,N,M,a,b,ways = 1; // 2 1 2
vector <int> result; // 3
//cout<<"\nenter T :\t";
cin>>T;
while(T--)
{
// cout<<"\nenter N and M :\t";
cin>>N>>M;
vector <vector <int> > g(N+1);
while(M--)
{
// cout<<"\nenter couples of friends :\t";
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
firesc(g,N,result);
cout<<result.size()<<' '; //cout<<"\n total routes :\t "<<result.size();
for(auto it = result.begin() ; it != result.end() ; ++it ) //int x : result
ways *= (*it);
cout<<ways%((1000000000+7))<<endl; //cout<<"\ntotal ways to select captains "<<ways;
result.clear();
/************************* for(auto it : g)
g[(*it)].clear();*******/
g.clear();
ways = 1;
}
return 0;
}