firescape route........WA

plzz…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 1000000007
using namespace std;
int dfs(int a,int b);
long long int routes,captain;
   int visited[100001];
    list<int> frnd[100001];
int main()
{
    int t,a,b,c,d,i,j,k,l,n,m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d  %d",&n,&m);
        c=2*m;
        
       for(i=1;i<=n;i++)visited[i]=0;
       
        for(i=1;i<=m;i++)
        {frnd[i].clear();
            for(j=1;j<=2;j++)
        {scanf("%d",&d);
          frnd[i].push_back(d);
        }
        }    
        routes=0;captain=0;
      if(m==0)
      printf("%d %d\n",n%M,1);
      else
      { list<int>::iterator it,jt;
        for(i=1;i<=m;i++)
        {
            it=frnd[i].begin();
            jt=it;
            ++it;
        
        dfs(*jt,*it);
        }    
        for(i=1;i<=n;i++)
       {
            if(visited[i]==0)routes++;
        }  routes=routes%M;
        captain=captain%M;  
        printf("%lld %lld\n",routes,captain);
          
        
    }  } return 0;
}
int dfs(int a,int b)
{
    if((visited[a]==0)&&(visited[b]==0))
    {visited[a]=1;visited[b]=1;routes++;
    if(captain==0)
    captain=captain+2;
    else
    captain=captain*2;
    return 0;
}
    else if((visited[a]==1)&&(visited[b]==0))
    {visited[b]=1;captain=captain+1;return 0;}
     else if((visited[a]==0)&&(visited[b]==1))
    {visited[a]=1;captain=captain+1;return 0;}
    return 0;
}

@wonder Check for this test case

1
6 5
1 2
3 4
6 5
2 6
3 1

It give 3 8 whereas the correct answer is 1 6.

3 Likes

thnx a lot…

If you find it useful then marked it as correct answer.

//