Checking is there a cycle in undirected graph with DFS