Блог пользователя aman_naughty

Автор aman_naughty, история, 6 лет назад, По-английски

Why does this solution fail at test 21 ?? code : 51444038. and this solution gives AC though code : 51444907 . Aren't the two doing the same thing??

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

If they would have been the same, then it wouldn't have failed on 21.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Can you help me matcoder without an 'h'??

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      I am sorry, but I tried to look at the codes. The only thing I found that would result in Wrong Answer is that no function in the second code has been called recursively (which may cause local flags to be set only once) and there are two conditions while checking (only 1 in the first code).
      Not sure though. But I'll have a closer look at it again if the query persists after a day too.

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится +3 Проголосовать: не нравится

        The two conditions in 2nd code are analogous to one condition in 1st code as s and p are connected and c==p case is handled as there is no self edge.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

If you want help, write nice code with comments and meaningful variable names. And explain your solution.

Your two solutions differ a lot. In your WA solution, you only consider edges $$$(p, s)$$$ that belong to some spanning tree. In other words, you don't go through all edges $$$(p, s)$$$. Note that there are $$$M$$$ edges while DFS function will run only $$$N$$$ times in a connected graph.