philolo1's blog

By philolo1, 14 years ago, In English

Hi,
I just tried to solve some problem and the compiler of codeforces gave a different result.
UPD: I minimized the code a little bit.

Here is one Code
#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <vector>
#include <set>
#include <math.h>
#include <algorithm>
#include <cstring>

using namespace std;

#define REP(a,b) for(int (a)=0;a<(int)b;a++)
#define PB push_back
#define s(a) scanf("%d",&a);
#define foreach(a,b) for(__typeof(b).begin() a  = b.begin(); a != b.end();a++)

vector<int> next[50];
bool visited[50];
int counter=0;

void DFS(int pos)
{
    if(!visited[pos])
    {
        visited[pos]=true;
       
        foreach(it,next[pos])
        {
            if(!visited[*it])
            {
                DFS(*it);
            }
        }
    }
}

int main()
{
    int N;int M;
    s(N);s(M);
   
    REP(n,M)
    {
        int a;
        int b;
        s(a);s(b);
        a--;
        b--;
        next[a].PB(b);
        next[b].PB(a);
    }
   
   
     if(N==M)
     {
        memset(visited,0,sizeof(visited));
       
        REP(n,N)
        {
            if(!visited[n])
            {
                counter++;
                DFS(n);
            }
        }
       
        cout<<"Counter "<<counter<<endl;
      }
      else
      {
        REP(n,N)
        {
            DFS(n);
        }
      } 
}

The input is
2 2
1 2
2 1

On my local machine it prints out 1, while on codeforces it prints out 2, which should be wrong.

  • Vote: I like it
  • +11
  • Vote: I do not like it

14 years ago, # |
  Vote: I like it 0 Vote: I do not like it
the weird thing is, if I delete the else part, the codeforces compiler gives yes.
14 years ago, # |
  Vote: I like it +3 Vote: I do not like it
It looks like it's a real bug, but we have to minimize the program before submitting the bug.
14 years ago, # |
  Vote: I like it 0 Vote: I do not like it
I have met this bug before.

foreach(it,v[pos])
{
    /* if you print something here, the result would change back to "YES". */
    if(!visited[*it])
    {
        DFS(*it);
    }
}
13 years ago, # |
  Vote: I like it 0 Vote: I do not like it

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49217

The bug was fixed, but, of course, we should wait for the next version for a fixed stable release.


It looks like 4.6 is a very buggy version...