Pagini recente » Cod sursa (job #2728377) | Cod sursa (job #2248792) | Rating Cazaciuc Valentin (alittlezz) | Infoarena Monthly 2014, Clasament Runda 4 | Cod sursa (job #3167774)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
int n, m, x, y;
const int M = 5e5 + 5;
int sel[M];
struct edge
{
int x, y, ind;
};
vector <edge> G[M];
vector <int> Q;
void Euler(int node)
{
while(G[node].size()){
edge K = G[node].back();
G[node].pop_back();
if(sel[K.ind] == 0)
{
sel[K.ind] = 1;
Euler(K.y);
}
}
Q.push_back(node);
}
int main()
{
fin >> n >> m;
for(int i = 1; i <= m; i++) {
fin >> x >> y;
G[x].push_back({x, y, i});
G[y].push_back({y, x, i});
}
for(int i = 1; i <= n; i++){
if(G[i].size() % 2 == 1)
{
fout << -1;
return 0;
}
}
Euler(1);
Q.pop_back();
for(auto x: Q) fout << x << ' ';
return 0;
}