undirected graph exists cycle or not problem