Pagini recente » Cod sursa (job #2890165) | Cod sursa (job #3210448) | Cod sursa (job #1169448) | Cod sursa (job #124423) | Cod sursa (job #1927148)
#include <bits/stdc++.h>
#define maxm 500100
#define maxn 100100
#define pb push_back
using namespace std;
int N,M,St[maxn],st;
bool B[maxn];
list<int> V[maxn];
void euler(int x){
St[st=1] = x;
while(st){
x = St[st];
for(int y;!V[x].empty();){
y = V[x].back();
V[x].pop_back();
V[y].erase(find(V[y].begin(),V[y].end(),x));
St[++st] = y;
x = y;
}
cout << St[st--] << ' ';
}
}
int main() {
ifstream cin("ciclueuler.in");
ofstream cout("ciclueuler.out");
cin >> N >> M;
for(int x,y;M--;){
cin >> x >> y;
V[x].pb(y);
V[y].pb(x);
}
for(int i = 1;i<=N;i++) if(V[i].size()%2) return cout << -1,0;
euler(1);
}