Pagini recente » Cod sursa (job #2453137) | Cod sursa (job #1925591) | Cod sursa (job #1632170) | Cod sursa (job #2186299) | Cod sursa (job #2056036)
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#define NMAX 100010
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
int N,M,i,x,y;
vector<int> v[NMAX];
stack<int>st;
int main()
{
f>>N>>M;
for(i = 1 ; i <= M ; ++i) f>>x>>y , v[x].push_back(y) , v[y].push_back(x);
for(i = 1 ; i <= N ; ++i)
if( v[i].size()%2 )
{
g << -1 ;
return 0;
}
st.push(1);
while( !st.empty() )
{
x=st.top();
while( !v[x].empty() )
{
y = v[x].back();
v[x].pop_back();
v[y].erase( find(v[y].begin(),v[y].end(),x) );
st.push(y);
x=y;
}
g<<st.top()<<' ';
st.pop();
}
return 0;
}