# fireescape WA

hey…guys…plzzzzzzzzzzzzzzzzzzzzz…wht the hell i m gettng wrng ans…

``````#include<cstdio>
#include<iostream>
#include<list>
#define M 10000007
using namespace std;

list<int> frnd[100006];
int y=0;
int visited[100006]={0};long long int captain=1;
//int dfs(int a);

int dfs(int a)
{

visited[a]=1;
y++;

list<int>::iterator it;
for(it=frnd[a].begin();it!=frnd[a].end();++it)
{
if(visited[*it]==0)
dfs(*it);
}
}

int main()
{
int t,a,b,c,i,j,k,l,n,m;
scanf("%d",&t);
while(t--)
{
int routes=0;
scanf("%d %d",&n,&m);

for(i=1;i<=m;i++)
{
scanf("%d  %d",&a,&b);
frnd[b].push_back(a);
frnd[a].push_back(b);
}

for(i=1;i<=n;i++)
visited[i]=0;

y=0,captain=1;

for(i=1;i<=n;i++)
{if(visited[i]==0)
{routes++;
dfs(i);
captain=captain*y;
y=0;}
}

captain=captain%M;

printf("%d %d\n",routes,captain);
for(i=1;i<=n;i++)
{frnd[i].clear();
visited[i]=0;}
routes=0;
captain=1;
}
return 0;
}``````

The first mistake that i can point out is that the value by which you have to take MOD is 10^9+7 and not 10^7+7…also captain is a long long variable…print it using “%lld”…will see if ne other bugs exist…hope this helps…

EDIT

also pls take care of the overflow of CAPTAIN var…by taking MOD after every multiplication…!!!

1 Like

hey u have declared mod as 100000007 it shoud be 10^9+7 i have edited it and got AC
you can check the result here http://www.codechef.com/viewsolution/2399108

thnx…finaly ac

thnx…finaly ac