check if graph is connected adjacency list