Pagini recente » Cod sursa (job #2818581) | Cod sursa (job #537191) | Cod sursa (job #645364) | Cod sursa (job #2678127) | Cod sursa (job #2551515)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream cin("ciclueuler.in");
ofstream cout("ciclueuler.out");
#define NMAX 100005
#define MMAX 500005
int n,m,from[MMAX],to[MMAX];
vector <int> g[NMAX];
bool usededge[MMAX];
int main()
{
int x,y;
cin>>n>>m;
for(int i=0; i<m; i++)
{
cin>>x>>y;
g[x].push_back(i);
g[y].push_back(i);
from[i]=x,to[i]=y;
}
for(int i=1; i<=n; i++)
{
if(g[i].size() & 1)
{
cout<<"-1\n";
return 0;
}
}
vector <int> stk;
vector <int> ans;
stk.push_back(1);
while(!stk.empty())
{
int node=stk.back();
if(!g[node].empty())
{
int aux=g[node].back();
g[node].pop_back();
if(!usededge[aux])
{
usededge[aux]=true;
int to= ::from[aux] ^ ::to[aux] ^ node;
stk.push_back(to);
}
}
else
{
stk.pop_back();
ans.push_back(node);
}
}
for(int i=0; i<ans.size()-1; i++)
{
cout<<ans[i]<<" ";
}
return 0;
}