T--o_o--T's blog

By T--o_o--T, history, 3 years ago, In English

Problem Link ,my code here Why I got WA? Please anyone can explain?

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
Rev. 2   Vote: I like it +10 Vote: I do not like it

Have you tried the following:

  • Write a very naive and simple solution to the problem (maybe exponential complexity) (if you can, you may also just copy someone else's solution)
  • Write a program to generate thousands of small (!) test cases
  • Using those two, find a test case where your program gives the wrong answer
  • Use print statements or a debugger to see where exactly your program does the wrong thing.

98% of WAs and REs can be resolved this way. People here don't have the time to delve into every code posted here, it's much harder to debug somebody else's code and being able to debug your own code is a valuable skill. It is also a very routine process that can be learned much faster than problem solving and algorithms.


Also, the ideone link is missing ':' in the URL.

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

    Sir, I agree with this process...but many a time it becomes very hard to generate test cases like when the input is a graph ....what to do then?

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

      Generating graphs is not that bad: if I want a connected graph, I usually generate a tree and then randomly add edges until I have the desired number of edges. It may be a bit tedious, but it's not too bad. If you have trouble implementing it fast, I suggest preparing a small library for that. Or use existing libraries, but don't ask me for recommendations because I haven't used any.

      If you have something more difficult, like a graph with some special property or something, I would generate inputs randomly until an input has the required property. Remember that you don't need anything super fancy or fast, you don't need uniform distribution or anything like that. Just a quick-and-dirty program that might reasonably generate any small input if you run it a few thousand times.

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

      You might be interested in jngen.h. If you've used testlib.h in Polygon before, it's the same syntax for most of the functions. In particular, with this library it becomes really easy to add extra modifiers like guaranteeing connected, acyclic, etc.