Pagini recente » Cod sursa (job #2006304) | Cod sursa (job #2674592) | Cod sursa (job #2738566) | Cod sursa (job #1279226) | Cod sursa (job #2531838)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int NMAX = 100005, MMAX = 500005;
vector<int> G[NMAX];
bool usedEdge[MMAX];
int from[NMAX], to[NMAX];
int main() {
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( G[i].size() % 2 == 1 ) {
fout<<"-1";
return 0;
}
}
vector<int> ans;
vector<int> st; //simulez apelul recursiv fml
st.push_back(1);
while( !st.empty() ) {
int node = st.back();
if( G[node].size() > 0 ) {
int i = G[node].back();
G[node].pop_back();
if( !usedEdge[i] ) {
int next;
if( from[i] == node )
next = to[i];
else
next = from[i];
usedEdge[i] = true;
st.push_back(next);
}
}
else {
ans.push_back(node);
st.pop_back();
}
}
for( const auto &it : ans )
fout<<it<<" ";
return 0;
}