I think (Although not sure) you should change scanf("%s",str) to scanf(" %s",str)
Your logic is correct…and it is very painful to read a code… So if it doesnt works then trll me i will try debugging it
I tried after updating my code but its still giving WA.
ALso, I am not always updating distances. I am checking the color of the nodes before updating. The nodes which have not been processed and are not in the queue are colored white while others are colored black. Before updating I am checking the color of the nodes
e.g. on line 16 I am checking ((x+1<m)&&(color[x+1][y]==1))
So I will push (x+1,y) only if it is not already processed and then I change color to black.
Hey Thanks! It did solve the problem. I have accepted your answer but can not upvote as I do not have enough reputation. Will upvote it when I am able to.