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

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

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
  • Проголосовать: не нравится

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

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

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 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.