Find all possible Euler cycles

I implemented an algorithm for finding the Euler cycle for a given initial vertex in an undirected graph (using DFS and removing visited edges), but it always returns only one path. How to change the algorithm to search for all possible Euler cycles for a vertex?

Here is the relevant code:

typedef int Graph[200][200]; // adjacency matrix int v, e; // vertex count, edge count ...... void DFS(Graph &G, int x) { int i; Push(x); for (i = 0; i < v; i++) if (G[i][x] > 0) { G[i][x] = 0; G[x][i] = 0; DFS(G, i); break; } 

}

+4
source share
2 answers

After the recursive call, you must again insert the edges that you deleted before, and get rid of the gap.

 void DFS(Graph &G, int x) { int i; Push(x); for (i = 0; i < v; i++) if (G[i][x] > 0) { G[i][x] *= -1; G[x][i] *= -1; DFS(G, i); G[i][x] *= -1; G[x][i] *= -1; } } 

Now you need to find out when you created the complete cycle to print it and move on to the next. This happens when you eliminate every edge of your schedule.

+4
source

You want to iterate over all the vertices.

-2
source

All Articles