Here is the problem: http://acm.timus.ru/problem.aspx?space=1&num=1930

Basically we have to find the shortest path form one node to another where the weights of the edges are 0 or 1.

Here is my code: http://paste.ubuntu.com/1527659/

Can anyone please help?

This is probably not the answer but, my first bfs solution was very similar to yours and it also got WA in test case 6. Then the DP solution passed. I am not sure, but may be we are missing something

sillyin our bfs implementation. If I can figure out the bug I'll share it with you.Thanks Xerxes.. By the way, Can i know your real name?

sure,I am Pallab. You know wasi and fahim bhaiya, right? They are my friends. :)

Yes i know know them! Now I know you as well :)

http://paste.ubuntu.com/1531247/ ... changed one line of your code, this will get AC :) why ? just debug your code with the following case, & you'll understand :

3 2 2 1 2 3 1 3

Yep! i got the problem! Thanks momnoy vaiayaa..