POJ 1041 John & #39; s trip (Euler loop)
Address: POJ 1041
The question must be a Lexicographic Order. Therefore, you must first sort the edge number so that each time you traverse the vertex with a smaller edge number. It is more convenient to use vector.
The Code is as follows:
#include
#include
#include
#include
#include #include
#include
#include
#include
using namespace std;#define LL long long#define pi acos(-1.0)const int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-9;const int MAXN=2000+10;int stk[2000000], deg[2000000], tot, vis[2000000];vector
>vec[MAXN];void add(int u, int v, int id){ vec[u].push_back(make_pair(id,v)); vec[v].push_back(make_pair(id,u));}void dfs(int u){ for(int i=0;i
0) puts("Round trip does not exist."); else{ for(i=1;i<=n;i++){ if(vec[i].size()) sort(vec[i].begin(),vec[i].end()); } dfs(1); if(tot
=0;i--){ printf("%d",stk[i]); if(i) printf(" "); } printf("\n"); } } } return 0;}