Pagini recente » Cod sursa (job #3217410) | Cod sursa (job #3220785) | Borderou de evaluare (job #1569473) | Clasament test4234234 | Cod sursa (job #1253510)
#include <cstdio>
#include <vector>
#include <stack>
using namespace std;
int i,j,m,n,x,y,nr;
stack <int> q,q1;
vector <int> v[100001];
void elr(int x)
{
vector <int>::iterator it;
vector <int>::iterator it1;
int i,nr,y;
if(!v[x].size()) {q1.push(x);q.pop();}
else
{it = v[x].begin();
while( it!=v[x].end())
{
q.push(*it);
if(!v[*it].empty()){
for(it1=v[*it].begin(); it1!=v[*it].end()&&(*it1)!=x; it1++);
if(*it1==x) v[*it].erase(it1);}
y=*it;
v[x].erase(it);
elr(y);
}}
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d %d",&n,&m);
if(m%2==1) printf("-1\n");
else{
for(i=1; i<=m; i++)
{
scanf("%d %d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
q.push(1);
elr(1);
while(!q.empty())
{
q1.push(q.top());
q.pop();
}
while(!q1.empty())
{
if(q1.size()!=1) printf("%d ",q1.top());
q1.pop();
}
}
return 0;
}