Pagini recente » Cod sursa (job #2828684) | Cod sursa (job #1600575) | Rating Moscaliuc Petruta (petty95) | Cod sursa (job #1430348) | Cod sursa (job #2819482)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int NMAX=100005;
int N, M, grad[NMAX];
vector<pair<int,int>> g[NMAX];
bool viz[NMAX], used[5*NMAX];
stack<int> st;
void dfs(int nod)
{
viz[nod]=true;
for(auto x: g[nod]){
if(viz[x.first]==false)
dfs(x.first);
}
}
void euler(int nod)
{
for(auto x: g[nod]){
if(used[x.second]==false){
used[x.second]=true;
euler(x.first);
}
}
st.push(nod);
}
int main()
{
fin>>N>>M;
int x, y, ind=0;
for(int i=1;i<=M;i++){
ind++;
fin>>x>>y;
g[x].push_back({y,ind});
g[y].push_back({x,ind});
grad[x]++;
grad[y]++;
}
for(int i=1;i<=N;i++){
if(grad[i]%2==1){
fout<<-1;
return 0;
}
}
/*
dfs(1);
for(int i=1;i<=N;i++){
if(viz[i]==false){
fout<<-1;
return 0;
}
}
*/
euler(1);
while(st.size()>=2){
fout<<st.top()<<' ';
st.pop();
}
fin.close();
fout.close();
return 0;
}