Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

why is not the value of y changing???

$
0
0

Hey guys...whys isn't the value of the "y" being changed up .... after the bfs() is being called up .Even though the value of "y" is being increased up in the bfs() function which is running.

#include<cstdio>
#include<iostream>
#include<vector>
#include<conio.h>
#include<list>
using namespace std;
int bfs(int a);
int visited[100006]={0};
list<int> v[100006];
list<int> l;
int routes;
long long int captain;
long long int y=1;
int main()
{
    int t,n,m,i,j,k,l,a,b,c;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d   %d",&n,&m);
        for(i=1;i<=m;i++)
        {
            scanf("%d  %d",&a,&b);
            v[a].push_back(b);
            v[b].push_back(a);
        }



       captain=1;long long int y=1;
        for(i=1;i<=n;i++)
        {
            if(visited[i]==0)
            {bfs(i);routes++;printf("ans   y    %d\n",y);captain=captain*y;}
        }        
        printf("%d %d\n",routes,captain);
    }
    getch();
}


int bfs(int a)
{  l.push_back(a);     
  visited[a]=1;
  list<int>::iterator it,c;
  while(l.empty()==false)
  {    c=l.begin();
     visited[*c]=1;
   printf("y    %d\n",y);
     for(it=v[*c].begin();it!=v[*c].end();++it)
      {if(visited[*it]==0){l.push_back(*it);}visited[*it]=1;}
      l.pop_front();   y++;


  }
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>