Pagini recente » Cod sursa (job #1024358) | Cod sursa (job #1371974) | Cod sursa (job #140722) | Cod sursa (job #2976309) | Cod sursa (job #2078929)
#include <bits/stdc++.h>
using namespace std;
FILE*f=fopen("ciclueuler.in","r");
FILE*g=fopen("ciclueuler.out","w");
stack<int>s;
list<int>l[100010];
list<int>r;
list<int>::iterator it;
int main()
{
int n,m,i,x=1,y,ok,j;
fscanf(f,"%d%d",&n,&m);
for (i=1;i<=m;i++){
fscanf(f,"%d%d",&x,&y);
l[x].push_back(y);
l[y].push_back(x);
}
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();
l[i].pop_back();
for (it=l[j].begin();it!=l[j].end();it++)
if (*it==i) {l[j].erase(it);break;}
s.push(j);
}
else{
r.push_back(i);
s.pop();
}
}
r.pop_back();
for (it=r.begin();it!=r.end();it++)
fprintf(g,"%d ",*it);
}
fclose(f);
fclose(g);
return 0;
}