Comments

(Ra ,Ca) position of A. Your idea seems correct but i will once more clear it up. when doing BFS from A calculate the minimum distance from (Ra , Ca) to cell(r , c). Then check if it is possible to go to cell (r , c) , until hitting one of the borders , then if we are on a border then the answer is yes , if not then try different path. i did it by doing DFS. I'm i bit lazy to check your code but i will share mine https://ideone.com/jgR1tm

in 983D when i input : 2 1 2 5 6 1 2 3 5 it outputs 3, but it should output 2. why does it output 3?

0

Can someone explain why does the dfs order work in problem D(div1)