is connected to check if a graph is connected