check source and destination cell of the matrix have value 1
if mat [ src . x ] [ src . y ] != 1 or mat [ dest . x ] [ dest . y ] != 1 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT visited = [ [ False for i in range ( COL ) ] for j in range ( ROW ) ] NEW_LINE