harryp's blog

By harryp, history, 4 months ago, In English,

PROBLEM LINK

MY CODE

I tried to solve this question using topological sort but I got only partial points. Please Help.

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

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by harryp (previous revision, new revision, compare).

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Did you get WA or TLE?

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

    It passed only some test cases. I got wrong answer for the remaining ones

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

      I think that the problem lies in your graph construction. You have to rethink what will be the edges of your graph.

      Also, you need to check if a node has been visited before performing toposort otherwise, your toposort function will print it twice.