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

Автор hackerbaba, история, 4 года назад, По-английски

Hello again. Just understood graphs. in this, the author gave a solution of dfs.

I was wondering, as to couldn't it be solved with Breadth First Search? Marking each level as one colour, and the other level as the second colour?

I gave a solution with BFS, but it's giving a wrong output.

Could you please help me out?

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

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

Why not? Here's a pretty simple BFS solution. https://www.hackerearth.com/submission/41568014/

Edit :I think it might be because the graph is not necessarily connected.