Pagini recente » Cod sursa (job #2878794) | Cod sursa (job #463033) | Cod sursa (job #830185) | | Cod sursa (job #1557709)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int NMax = 1e5 + 5;
int Grad[NMax];
vector < int > A;
list < int > G[NMax];
stack < int > S;
int main(){
int n, m, node, x, y, go;
fin >> n >> m;
while(m--){
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
Grad[x]++; Grad[y]++;
}
for(int i = 1; i <= n; i++){
if(Grad[i] % 2){
fout << -1;
return 0;
}
}
S.push(1);
while(!S.empty()){
node = S.top(); S.pop();
while(!G[node].empty()){
go = G[node].front();
for(list < int > ::iterator it = G[go].begin(); it != G[go].end(); it++){
if(*it == node){
G[go].erase(it);
break;
}
}
G[node].pop_front();
S.push(node);
node = go;
}
A.push_back(node);
}
for(auto it: A) fout << it << " ";
return 0;
}