through adjacency matrix