Pagini recente » Istoria paginii runda/eusebiuoji2016cls9/clasament | Cod sursa (job #1891169) | Cod sursa (job #1300257) | Cod sursa (job #605222) | Cod sursa (job #1916412)
#include <fstream>
#include <iostream>
#include <algorithm>
#include <list>
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
list <int> ls[100005];
int n, m, x, y, i;
int stiva[500005], vf;
int main() {
f >> n >> m;
while (m--) {
f >> x >> y;
ls[x].push_back(y);
ls[y].push_back(x);
}
for (i = 1; i <= n; i++)
if (ls[i].size()%2 == 1) {
g<<-1;
return 0;
}
stiva[vf=1] = 1;
while (vf > 0) {
x = stiva[vf];
cout<<1;
while (ls[x].size() > 0) {
y = ls[x].front();
ls[x].pop_front();
ls[y].erase( find(ls[y].begin(), ls[y].end(), x) );
stiva[++vf] = y;
x = y;
}
g << stiva[vf--]<<' ';
}
return 0;
}