check source and destination cell of the matrix have value 1
if ( ! mat [ src . x ] [ src . y ] ! mat [ dest . x ] [ dest . y ] ) return -1 ; bool visited [ ROW ] [ COL ] ; memset ( visited , false , sizeof visited ) ;