Pagini recente » Cod sursa (job #581784) | Cod sursa (job #2256288) | Cod sursa (job #2959459) | Cod sursa (job #2735877) | Cod sursa (job #2178973)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100010, MMAX = 500010;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
vector<int> V[NMAX];
int F[NMAX],T[NMAX];
int N,M;
bool used[MMAX];
int main(){
fin >> N >> M;
for (int i = 0; i < M;i++){
int x,y;
fin >> x >> y;
V[x].push_back(i);
V[y].push_back(i);
F[i] = x;
T[i] = y;
}
for(int i = 1; i <= N;i++) if (V[i].size()&1) return fout <<-1,0;
vector<int> ans;
vector<int> stk;
stk.push_back(1);
while(!stk.empty()){
int node = stk.back();
//cout << node << " ";
if (!V[node].empty()){
int e = V[node].back();
V[node].pop_back();
if (!used[e]){
used[e] = 1;
int to = ::F[e] ^ ::T[e] ^ node;
stk.push_back(to);
}
}
else{
stk.pop_back();
ans.push_back(node);
}
}
for (auto it:ans) fout << it << " ";
return 0;
}