if we get { 0 , 0 } before the end of loop then returns false . Because it means we didn 't traverse all the cells
if ( grid [ startx ] [ starty ] . first == -1 and grid [ startx ] [ starty ] . second == -1 ) return false ;