Pagini recente » Cod sursa (job #2420654) | Cod sursa (job #1897115) | Cod sursa (job #1249173) | Cod sursa (job #2671169) | Cod sursa (job #2159360)
#include <bits/stdc++.h>
#define nmax 100002
using namespace std;
ifstream fin ("ciclueuler.in");
ofstream fout ("ciclueuler.out");
vector <pair<int,int>> G[nmax];
vector <int> ans;
stack <int> stk;
int n,m;
int main()
{
int a,b;
fin>>n>>m;
for(int i=1;i<=m;++i){
fin>>a>>b;
G[a].push_back({b,G[b].size()});
G[b].push_back({a,G[a].size()-1});
}
for(int i=1;i<=n;++i)
if(G[i].size() & 1){
fout<<-1<<'\n';
return 0;
}
stk.push(1);
cout<<G[1].size();
while(!stk.empty()){
int w=stk.top();
if(!G[stk.top()].empty()){
int q=G[stk.top()].back().first;
int qq=G[stk.top()].back().second;
G[stk.top()].pop_back();
int ww=G[q].size();
int www=G[q][qq].first;
if(G[q].size()>qq){
stk.push(q);
}
}
else{
ans.push_back(stk.top());
stk.pop();
}
}
for(int i=0;i<ans.size()-1;++i)fout<<ans[i]<<' ';
fout<<'\n';
return 0;
}