You are not logged in. Please login at to post your questions!


where have I made mistake?

I made a silly mistake, but I am unable to find it. I am not getting correct answer for the second test case. Please help.


p.s. Mistake is in variable k I think

asked 23 Jul '15, 11:38

dragonemperor's gravatar image

accept rate: 10%

you are pushing the same variable twice on the queue list.

For example, in the second test case:

initially        qq = {0};

after loop 1, qq = {1,2};

after loop 2, qq = {2,2}, which is incorrect;

add a variable done[] to avoid this.

This passes the given test cases


answered 23 Jul '15, 16:50

rajeevkgprk's gravatar image

accept rate: 17%

Thanks, this now passes the given test cases, but not the problem. Can you tell me where else I have made mistake?

(23 Jul '15, 20:09) dragonemperor3★

dfs , bfs

I think dfs is easier and less error prone.

In BFS, you are supposed to iterate over the adjacent vertices, but in your code you were popping them(line 46). I cannot prove it but it might be deleting necessary connections.


answered 24 Jul '15, 15:09

rajeevkgprk's gravatar image

accept rate: 17%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 23 Jul '15, 11:38

question was seen: 527 times

last updated: 24 Jul '15, 15:09