divyanshchoukse443's blog

By divyanshchoukse443, history, 5 years ago, In English

I am trying to get better at cp, recently I stumbled upon a problem that I tried to solve by using topological sort but two of the test cases are failing and I can't figure out what is wrong. Please help me out. Link to problem is:https://cses.fi/problemset/task/1680 my code: https://cses.fi/paste/c8431ed4e67b8c202fc06d/

| Write comment?
»
5 years ago, hide # |
 
Vote: I like it +12 Vote: I do not like it
  1. What you have written in the title, write it in the body of the blog
  2. Give the problem Link
»
5 years ago, hide # |
 
Vote: I like it 0 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.