Pagini recente » Cod sursa (job #3147969) | Cod sursa (job #1812644) | Cod sursa (job #2780807) | Cod sursa (job #1183678) | Cod sursa (job #1236810)
#include<fstream>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
int n,m,i,x,y;
vector<int> l[100100];
stack<int> st;
int main()
{
f>>n>>m;
for(i=1;i<=m;++i)
{
f>>x>>y;
l[x].push_back(y);
l[y].push_back(x);
}
for(i=1;i<=n;++i)
if((!l[x].size())||(l[x].size()&1))
{
g<<"-1\n";
return 0;
}
st.push(1);
while(!st.empty())
{
x=st.top();
if(!l[x].size())
{
st.pop();
if(!st.empty())
g<<x<<" ";
}
else
{
y=l[x].back();
st.push(y);
l[x].pop_back();
l[y].erase(find(l[y].begin(),l[y].end(),x));
}
}
g<<'\n';
return 0;
}