Pagini recente » Cod sursa (job #547717) | Cod sursa (job #2175524) | Cod sursa (job #2479019) | Cod sursa (job #887620) | Cod sursa (job #2824831)
#include <bits/stdc++.h>
using namespace std;
const int nmax=int(1e5);
vector <pair<int,int>> adj[nmax];
vector <int> ans;
int elim[5*nmax+1];
int n,m;
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d %d ",&n,&m);
for(int i=1,x,y;i<=m;++i){
scanf("%d %d ",&x,&y);
adj[x].push_back({y,i});
adj[y].push_back({x,i});
}
for(int i=1;i<=n;++i)
if(adj[i].size()%2==1){
cout<<"-1";
return 0;
}
stack <int> st;
st.push(1);
while(!st.empty()){
int nod=st.top();
if(adj[nod].size()){
int x=adj[nod][adj[nod].size()-1].second;
if(!elim[x]){
elim[x]=1;
st.push(adj[nod][adj[nod].size()-1].first);
}
adj[nod].pop_back();
}
else{
ans.push_back(nod);
st.pop();
}
}
for(auto x:ans)
cout<<x<<" ";
}