Pagini recente » Cod sursa (job #229205) | Cod sursa (job #598410) | Cod sursa (job #2130313) | Istoria paginii runda/abcde/clasament | Cod sursa (job #1889785)
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
vector<int>ls[100005],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);
ok = 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;
//g<<1;
}
//g<<'\n';
sol.push_back(stiva.top());
stiva.pop();
}
for (auto &it:sol)
printf("%d ", it);
return 0;
}