Saksham_Sahgal's blog

By Saksham_Sahgal, history, 2 years ago, In English

I get this when i submit code —

but when i run my exact same testcase in test against custom input window i get —

which is the correct output.

here is my submission — Submission

what am i doing wrong?

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

| Write comment?
»
2 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Maybe it is occurring because of the global stuff you have declared . Not resetting them for each test case would lead to problems.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I tried clearing global variables but now it gives TLE :< Submission

    • »
      »
      »
      2 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Make things local, pass things by reference in your helper functions.

      • »
        »
        »
        »
        2 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        ok , but i don't find anything wrong in declaring it global and clearing it for testcases , why would it anyway lead to TLE , but declaring it each time locally would pass?

        • »
          »
          »
          »
          »
          2 years ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          I have not went through your code, but see suppose you have

          vector<int>graph[N]
          

          , as graph adjacency list representation of graph and N is of 1e5 order. You have made it global.

          Clearing it whole for each case till N may give you TLE.

          But if you clear it till your required input n, then it may not give TLE.

          I have faced TLE lot of time because of clearing everytime time for whole graph.

          So either clear till n(given input size) or make it local and pass it by reference in required helper functions.

          Sorry I havent seen your code, I will see it later.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

don't get it

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

not got any reason