Pagini recente » Istoria paginii runda/roz | Cod sursa (job #1203500) | Cod sursa (job #1883389) | Cod sursa (job #2149276) | Cod sursa (job #1864631)
#include <fstream>
#include <vector>
#include <stack>
#include <list>
#include <algorithm>
#include <queue>
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
vector <int> rasp;
list <int> ls[100005];
int n, m, x, y, i, l;
bool viz[100005];
stack<int>stiva;
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 || ls[i].size() == 0) {
g << "-1";
return 0;
}
stiva.push(1);
while (stiva.empty()==0) {
x = stiva.top();
while (ls[x].size()) {
y = ls[x].front();
stiva.push(y);
ls[x].pop_front();
ls[y].erase(find(ls[y].begin(),ls[y].end(), x));
x = y;
}
rasp.push_back(stiva.top());
stiva.pop();
}
vector<int>::iterator it;
for(it = rasp.begin(); it != rasp.end(); it++)
g << *it << ' ';
return 0;
}