In this code, you can create an undirected graph and add its edges; then, the code finds all cycles also cycles of the cycle in the graph and print its members. The main idea is finding one cycle at the time and destroy it, then repeat this process until no cycle will be found in the graph. in the final, your graph will not have any cycle in it. For example, consider the following undirected graph:
When run the code, you see this out put
cycle 1: [2, 3, 4, 1, 0]
cycle 2: [9, 8, 7]
cycle 3: [5, 10, 9, 8, 7, 2, 3]
cycle 4: [6, 5, 10, 9, 8, 7, 2, 3, 4]