No one is going to check my  your code  ....
Don't submit my code directly to spoj ,,,,,,,Learn  from it.......and then
make your own code..


#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cassert>
using namespace std;


   /*  int size=visited.size();
    cout<<size<<endl;
           for(j=0;i<size;j++)
           {
            if(visited[w[i][j]]=visited[i])
            {
                return 1;
            }
            else if(!visited[w[i][j]])
            {
                Q.push(w[i][j]);
                if(visited[i]==1)
                    visited[w[i][j]]=2;
                else
                visited[w[i][j]]=1;
            }
        }


*/

int   bfs(vector<vector<int> > &w ,vector<int> &visited,int start_vertex)
 {
      int i,j;
      queue<int> Q;
      Q.push(start_vertex);
      visited[start_vertex] =1;
      while(!Q.empty())
      {
           int i = Q.front();                                          //
get the tail element from queue
           Q.pop();
           vector<int>::iterator it;
           for(it=w[i].begin();it!=w[i].end();it++)
           { //pushing neighbouring nodes of current nodes
                if(visited[*it]==visited[i])
                    return 1;

                else  if(!visited[*it])
                {
                      Q.push(*it);
                      if(visited[i]==1)
                          visited[*it]=2;
                      else
                          visited[*it]=1;
                }

           }

      }
      return 0;
 }


/* Main code starts from here */
    int main()
    {

    int i,j,a,b,N,tc;
    int k,check=0;

    scanf("%d",&tc);
    int p=1;
    while(tc--)
    {
        scanf("%d%d",&N,&k);
        if(N==0)
          return 0;
        vector<vector<int> >  w(N,vector<int>(0));
              for(i=0;i<k;i++)
                    {
                       scanf("%d%d",&a,&b);
                          w[a-1].push_back(b-1);        //v[a-1][j]=b-1
                             w[b-1].push_back(a-1);
                       }
                 vector<int > visit(N,0);

        for(i=0;i<N;i++)
        {
            if(!visit[i])
            {

                              check=bfs(w,visit,i);
                              if(check==1)
                              {
                                  printf("Scenario #%d:\nSuspicious bugs
found!\n",p);
                                  p++;
                                  break;
                              }
                        }
               }

               if(check==0)
                   {
                  printf("Scenario #%d:\nNo suspicious bugs found!\n",p);
                  p++;
                }
        }

    return 0;
}


On Mon, Jan 23, 2012 at 2:57 PM, D!leep Gupta <dileep.smil...@gmail.com>wrote:

>
> guys plz help...
> http://www.spoj.pl/problems/BUGLIFE/
>
> i m getting wrong ans can any one give me the test case on which my code
> giving wrong... i m unable to find out
>
> #include<stdio.h>#define MAX 2500int front=-1;int rear=-1;int q[MAX];
>  void addq(int n)
>         {
>                 q[++rear]=n;
>         }int delq()
>         {
>         if(front==rear)
>                 return -1;
>         else
>                 return q[++front];
>         }
>  int main(){int t,k=0;int num,action,m,n;int i,j;scanf 
> <http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html>("%d",&t);while(t--)
>         {
>         k++;
>         front=-1;
>         rear=-1;
>         int error=0;
>         int visit[MAX]={0};
>         visit[0]=1;
>         scanf 
> <http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html>("%d%d",&num,&action);
>         int n=num;
>         int arr[num][num],a[num];
>         for(i=0;i<num;i++)
>                 {
>                         a[i]=-2;
>                         for(j=0;j<num;j++)
>                                 arr[i][j]=0;
>                 }
>         while(action--)
>                 {
>                         scanf 
> <http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html>("%d%d",&m,&n);
>                         arr[m-1][n-1]=arr[n-1][m-1]=1;
>                 }
>         int l;
>         addq(0);
>         while(n--)
>                 {
>
>                         if((i=delq())==-1)
>                                 {for(l=0;l<num;l++)
>                                         if(a[l]==-2)
>                                         {
>                                                 addq(l);
>                                                 n++;
>                                                 visit[l]=1;
>                                                 break;
>                                         }
>                                 }
>                         else
>                         { a[i]=i;
>                         for(j=i+1;j<num;j++)
>                         {
>                                 if(arr[i][j] && i!=j)
>                                 {
>                                         if(visit[j]==visit[i])
>                                                 {
>                                                 error=1;
>                                                 break;
>                                                 }
>                                         else if(!visit[j])
>                                                 {
>                                                 visit[j]=-visit[i];
>                                                 addq(j);
>                                                 }
>                                 }
>                         }
>                         }
>                 if(error) break;
>                 }
>         printf 
> <http://www.opengroup.org/onlinepubs/009695399/functions/printf.html>("Scenario
>  #%d\n",k);
>         if(error)
>                 printf 
> <http://www.opengroup.org/onlinepubs/009695399/functions/printf.html>("Suspicious
>  bugs found!\n");
>         else    printf 
> <http://www.opengroup.org/onlinepubs/009695399/functions/printf.html>("No 
> suspicious bugs found!\n");
>         }return 0;}
>
>
> --
> Dileep Kumar
> 3rd year
> Computer Science & Engineering
> NIT, Allahabad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*Anil  Arya,
Computer Science *
*Motilal Nehru National Institute of Technology,Allahabad .
*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to