Pagini recente » Cod sursa (job #2605051) | Cod sursa (job #1398303) | Cod sursa (job #2923133) | Cod sursa (job #364399) | Cod sursa (job #2845476)
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAX 100005
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
queue < pair < int, int > > v[MAX];
vector < int > R;
bool viz[MAX];
void dfs(int nod);
int main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m, x, y, i, nr[MAX];
fin >> n >> m;
for(i = 1; i <= n; i++) nr[i] = 0;
for(i = 1; i <= m; i++)
{
fin >> x >> y;
if(x != y) v[x].push({y, i}), v[y].push({x, i});
else nr[x]++;
}
for(i = 1; i <= n; i++) if(v[i].size() % 2 == 1) i = n + 1;
if(i == n + 2) fout << -1;
else
{
dfs(1);
for(auto it:R)
{
fout << it << ' ';
while(nr[it] != 0) fout << it << ' ', nr[it]--;
}
}
return 0;
}
void dfs(int nod)
{
int x;
while(v[nod].empty() == 0)
{
if(viz[v[nod].front().second] == 0)
{
x = v[nod].front().first, viz[v[nod].front().second] = 1, v[nod].pop();
dfs(x);
}
else v[nod].pop();
}
R.pb(nod);
}