You are not logged in. Please login at www.codechef.com to post your questions!

×

[closed] 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);}
}

asked 22 Jul '13, 19:21

wonder's gravatar image

2★wonder
361183769
accept rate: 0%

closed 22 Jul '13, 21:53

kunal361's gravatar image

4★kunal361
6.0k133272

koi to help karo.......:(

(22 Jul '13, 19:50) wonder2★

The question has been closed for the following reason "Duplicate Question" by kunal361 22 Jul '13, 21:53


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

link

answered 22 Jul '13, 21:52

nitish1402's gravatar image

3★nitish1402
31115
accept rate: 0%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,070

question asked: 22 Jul '13, 19:21

question was seen: 423 times

last updated: 22 Jul '13, 21:53