we can use multisource bfs but with some modifications. Here is my accepted code link.
Nothing major. I too used ms bfs
Just store minimum distance from any source and exit as soon as you find an already visited child.
check this code: CodeChef: Practical coding for everyone
can someone help me out where my code is wrong.
This is the best explanation