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

×

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

asked 22 Jul '13, 20:59

wonder's gravatar image

2★wonder
361183769
accept rate: 0%

closed 22 Jul '13, 21:50

kunal361's gravatar image

4★kunal361
6.0k133272

The question has been closed for the following reason "The question is answered, right answer was accepted" by kunal361 22 Jul '13, 21:50


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..!!!

link

answered 22 Jul '13, 21:42

kunal361's gravatar image

4★kunal361
6.0k133272
accept rate: 21%

edited 22 Jul '13, 21:44

thnx............finaly ac

(22 Jul '13, 21:47) wonder2★

glad could help..:)

(22 Jul '13, 21:49) kunal3614★

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

link

answered 22 Jul '13, 21:42

nitish1402's gravatar image

3★nitish1402
31115
accept rate: 0%

thnx............finaly ac

(22 Jul '13, 21:48) wonder2★

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, 20:59

question was seen: 494 times

last updated: 22 Jul '13, 21:50