Pagini recente » Cod sursa (job #1547384) | Cod sursa (job #2147899) | C.C. | Cod sursa (job #2971821) | Cod sursa (job #2082630)
#include <bits/stdc++.h>
using namespace std;
FILE*f=fopen("ciclueuler.in","r");
FILE*g=fopen("ciclueuler.out","w");
stack<int>s;
list<pair<int,int> >l[100010];
list<int>::iterator it;
int b[500010];
int main()
{
int n,m,i,x=1,y,ok,j,k;
fscanf(f,"%d%d",&n,&m);
for (i=1;i<=m;i++){
fscanf(f,"%d%d",&x,&y);
l[x].push_back(make_pair(y,i));
l[y].push_back(make_pair(x,i));
}
ok=1;
for (i=1;i<=n;i++)
if (l[i].size()%2==1) {ok=0;break;}
if (!ok) fprintf(g,"-1");
else{
s.push(1);
while (!s.empty()){
i=s.top();ok=l[i].size();
if (!l[i].empty()){
j=l[i].back().first;
k=l[i].back().second;
l[i].pop_back();
if (!b[k]){
b[k]=1;
s.push(j);
}
}
else{
if (s.size()!=1) fprintf(g,"%d ",i);
s.pop();
}
}
}
fclose(f);
fclose(g);
return 0;
}