Help required in Atcoder ABC170 problem F

You can see question here.
I am doing bfs starting with x1,y1 and adding all points that are at distance (dist[x1][y1]+1) to the queue. I’m breaking the loop whenever we get some point which is calculated, that is which has distance<= current vertex or ‘@’.
My submission is code is failing in three test cases .Im unable to figure out the mistake.