Pagini recente » Cod sursa (job #400649) | Cod sursa (job #837704) | Cod sursa (job #3263355) | Cod sursa (job #89579) | Cod sursa (job #2162755)
#include <bits/stdc++.h>
#define Nmax 100001
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
list <int> G[Nmax];
stack <int> st;
list <int> ans;
int n,m;
void Euler()
{
list <int> :: iterator it;
int w,x;
st.push(1);
while(!st.empty())
{
x=st.top();
if(!G[x].empty())
{
w=*G[x].begin();
G[x].pop_front();
for(it=G[w].begin();*it!=x;++it);
G[w].erase(it);
st.push(w);
}
else
{
ans.push_back(x);
st.pop();
}
}
}
int main()
{
int x,y,i;
f>>n>>m;
while(m--)
{
f>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
for(i=1;i<=n;i++)
if(((int)G[i].size())&1)
{
g<<-1;
return 0;
}
Euler();
for(list <int> :: iterator it=ans.begin();it!=--ans.end();++it)
g<<*it<<' ';
return 0;
}