hasanraj3100's blog

By hasanraj3100, history, 22 months ago, In English

I submitted a solution for the problem: E. Bertown roads My submission is: 289121858

ideone Link of the same submission: https://ideone.com/Pn4Wdh

The checker comment I got is:

wrong output format Unexpected end of file — int32 expected

Input:

6 8
1 2
2 3
1 3
4 5
4 6
5 6
2 4
3 5

Participant's output:

1 2
1 3

Jury's Answer:

6 4
4 5
5 6
5 3
3 2
2 1
1 3
2 4

But if I run the same code with same input on online compilers and my machine, it produces correct output (N lines). You can check the ideone link I provided, even this one producing the correct output!

I even tried changing the code and replaced the map with set. Here is that submission: 289122463

But the same issue occurs. My code produces only two lines on codeforces but N lines on other compilers.

What am I missing?

  • Vote: I like it
  • -17
  • Vote: I do not like it

| Write comment?
»
22 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

You have to initialize the Arrays first. Change your code to this

Graph::Graph(int n) {
    V = n + 1;
    adj = new list<int>[V];
    visited = new bool[V]();
    tin = new int[V]();
    low = new int[V]();
}

  • »
    »
    22 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    But your way of initializing is doing nothing on the map or set, right?

    Also if my way of initializing was wrong, other compiler wouldn't have worked, right? And I used the same syntax in other problems on codeforces, and it worked.

    for example this submission: 285438974

    • »
      »
      »
      22 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Someone correct me if I'm wrong ,but you're just getting unexpected behavior if you don't initialize an array, so maybe you got lucky or the test cases didn't really exploit that. Also sets and maps don't require initialization beyond just declaring them.

      • »
        »
        »
        »
        22 months ago, hide # ^ |
         
        Vote: I like it +4 Vote: I do not like it

        It's worth noting codeforces compiles your code with the -O2 flag, so it's not surprising for undefined behaviour to yield different results on codeforces than multiple other test environments which don't use it. Best to avoid undefined behaviour in general rather than hoping the compiler will do what you need

»
22 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it
if (!visited[v]) {
      dfs(v, node); ....

You have not initialized the visited array.