Pagini recente » Cod sursa (job #3269745) | Cod sursa (job #2210673) | Cod sursa (job #2479003) | Cod sursa (job #3005448) | Cod sursa (job #1928005)
#include <bits/stdc++.h>
#define maxm 500100
#define maxn 100100
#define pb push_back
using namespace std;
int N,M,St[maxm],st;
list<int> V[maxn];
string rs;
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;
}
rs+=to_string(St[st--]);
rs+=" ";
}
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
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);
cout << rs;
}