Test instructions
For a diagram, a scheme that starts from point 1 and passes through all sides exactly two times to point 1, the data is guaranteed to have a solution.
Analysis:
Euler loop, change the number of times just fine.
Code:
POJ 2230
//sep9
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=10024;
const int maxm=50048;
int HEAD[MAXN];
int used[maxm*2];
vector<int> path;
struct Edge
{
int v,nxt;
} EDGE[MAXM*2];
int e,n,m;
void Dfs (int u)
{for
(int i=head[u];i!=-1;i=edge[i].nxt) {
int cur=i|1;
if (used[cur]<2) {
int v=edge[i].v;
++used[cur];
DFS (v);
Path.push_back (v);
}} int main ()
{
scanf ("%d%d", &n,&m);
int i;
e=0;
memset (head,-1,sizeof (head));
memset (used,0,sizeof (used));
Path.clear ();
for (i=1;i<=m;++i) {
int u,v;
scanf ("%d%d", &u,&v);
edge[e].v=v;edge[e].nxt=head[u];head[u]=e++;
edge[e].v=u;edge[e].nxt=head[v];head[v]=e++;
}
DFS (1);
Reverse (Path.begin (), Path.end ());
printf ("1\n");
For (I=0;i<path.size (); ++i)
printf ("%d\n", Path[i]);
return 0;