Pagini recente » Cod sursa (job #340411) | Cod sursa (job #1682609) | Cod sursa (job #656839) | Cod sursa (job #874501) | Cod sursa (job #1861615)
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
using namespace std;
stack <int> st;
list <int> v[100010], ans;
void euler(int node)
{
st.push(node);
while (!st.empty())
{
int vf = st.top();
while (v[vf].size())
{
int next = v[vf].front();
v[vf].pop_front();
v[next].erase(find(v[next].begin(), v[next].end(), vf));
st.push(next);
vf = next;
}
ans.push_back(st.top());
st.pop();
}
}
int n, m, x, y;
int main()
{
freopen("ciclueuler.in", "r", stdin);
freopen("ciclueuler.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i=1; i<=m; i++)
{
scanf("%d%d", &x, &y);
v[x].push_back(y);
v[y].push_back(x);
}
for(int i=1; i<=n; i++)
{
if(v[i].size()==0 or v[i].size()%2==1)
{
printf("-1");
return 0;
}
}
euler(1);
ans.pop_back();
list<int>::const_iterator i;
for(i = ans.begin(); i != ans.end(); ++i)
printf("%d ", *i);
return 0;
}