Pagini recente » Cod sursa (job #3126901) | Cod sursa (job #598690) | Cod sursa (job #538393) | Cod sursa (job #2416236) | Cod sursa (job #1889793)
#include <cstdio>
#include <vector>
#include <list>
#include <stack>
#include <algorithm>
using namespace std;
list<int>ls[100005];
vector<int>sol;
bool viz[100005],ok;
int n, m,i,j,x,y;
stack<int>stiva;
int main() {
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d %d\n", &n, &m);
while (m--) {
scanf("%d %d\n", &x,&y);
ls[x].push_back(y);
ls[y].push_back(x);
}
for (i = 1; i<= n; i++)
if (ls[i].size()%2==1) {
printf("-1");
return 0;
}
stiva.push(1);
while (stiva.empty()==0) {
x = stiva.top();
while (ls[x].size() > 0) {
y = ls[x].front();
stiva.push(y);
ls[x].erase(ls[x].begin());
ls[y].erase(find(ls[y].begin(), ls[y].end(), x));
x = y;
}
sol.push_back(stiva.top());
stiva.pop();
}
for (auto &it:sol)
printf("%d ", it);
return 0;
}