Pagini recente » Cod sursa (job #3032195) | Cod sursa (job #2718182) | Cod sursa (job #2371396) | Cod sursa (job #1691935) | Cod sursa (job #1154022)
#include<cstdio>
#include<algorithm>
#include<vector>
#include<stack>
#define maxn 100005
using namespace std;
stack <int> stiv;
vector <int> G[maxn];
int x,y,n,m,ok=1;
void Fleury(){
int x,y;
stiv.push(1);
while(stiv.size()){
x=stiv.top();
if(G[x].size()==0){
printf("%d ",x);
stiv.pop();
}
else{
y=*G[x].begin();
G[x].erase(G[x].begin());
G[y].erase(find(G[y].begin(),G[y].end(),x));
stiv.push(y);
}
}
}
int main(){
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d%d", &n,&m);
for(int i=1;i<=m;++i){
scanf("%d%d", &x, &y);
G[x].push_back(y);
G[y].push_back(x);
}
for(int i=1;i<=n;++i)
if(G[i].size() %2){
ok=0;
printf("-1");
break;
}
if(ok)
Fleury();
return 0;
}