Pagini recente » Cod sursa (job #2915153) | Cod sursa (job #805243) | Cod sursa (job #468205) | Cod sursa (job #2541927) | Cod sursa (job #2637826)
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int NMAX=100005, MMAX=500005;
vector<int> G[NMAX];
bool usedEdge[MMAX];
int from[MMAX],to[MMAX];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
fin>>n>>m;
for(int i=0;i<m;i++)
{
int x,y;
fin>>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(SZ(G[i])&1)
{
fout<<-1;
return 0;
}
vector<int> ans;
vector<int> stk;
stk.push_back(1);
while(!stk.empty())
{
int node=stk.back();
if(!G[node].empty())
{
int e=G[node].back();
G[node].pop_back();
if(!usedEdge[e])
{
usedEdge[e]=true;
int tto=from[e]^to[e]^node;
stk.push_back(tto);
}
}
else
{
stk.pop_back();
ans.push_back(node);
}
}
for(int i=0;i<SZ(ans)-1;i++)
fout<<ans[i]<<" ";
return 0;
}