PHANTOM_23's blog

By PHANTOM_23, history, 11 months ago, In English

Problem

Submission

Checker comment "wrong answer Test 226: Expected -1, got a Tree !! (test case 226)" I have checked the -1 condition in the beginning

if(m<n || m>n*(n+1ll)/2ll)
    {
        cout<<"-1\n";
        return;
    }
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
11 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Hey man your code trips up on the one node cas when n=1 you still fall into the make edges logic and end up printing a false edge like 1 1 so the judge thinkse you handed it a tree instead of just a single node

to fix this slam in an early check if n == 1 then if m == 1 print 1 and return else print -1 and return and only run your normal tree building code when n > 1.