connect all 4 adjacent cell to current cell
if ( isSafe ( i , j + 1 , M ) ) : NEW_LINE INDENT g . addEdge ( k , k + 1 ) NEW_LINE DEDENT if ( isSafe ( i , j - 1 , M ) ) : NEW_LINE INDENT g . addEdge ( k , k - 1 ) NEW_LINE DEDENT if ( j < N - 1 and isSafe ( i + 1 , j , M ) ) : NEW_LINE INDENT g . addEdge ( k , k + N ) NEW_LINE DEDENT if ( i > 0 and isSafe ( i - 1 , j , M ) ) : NEW_LINE INDENT g . addEdge ( k , k - N ) NEW_LINE DEDENT