firescape route WA

lzz…guys help me out…whats wrong in my code eveytime gettting WA…though i have checked for a couple of test cases.

#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 routes,captain=1;
int dfs(int a);
int main()
{
    int t,a,b,c,i,j,k,l,n,m;
    scanf("%d",&t);
    while(t--)
    {
        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);
        }y=0;
        for(i=1;i<=n;i++)
        {if(visited[i]==0){routes++;dfs(i);captain=captain*y;y=0;}
        }
        printf("%lld %lld\n",routes%M,captain%M);
        for(i=1;i<=n;i++){frnd[i].clear();visited[i]=0;}routes=0;captain=1;
    }
    return 0;
}


int dfs(int a)
{  
    if(visited[a]==1)
    return 0;
    y++;    visited[a]=1;


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

koi to help karo…:frowning:

http://www.codechef.com/viewsolution/2399108
check out this code just edited your code littlebuit and got AC
1.change ints to long long
2.mod should be 10^9+7
3.apply mod like this captain=(captain%m*y%m)%m

//