check if adjacency matrix is connected