Pagini recente » Cod sursa (job #345307) | Cod sursa (job #2820400) | Cod sursa (job #2845013) | Cod sursa (job #2372834) | Cod sursa (job #2845467)
#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 < int > v[MAX];
vector < int > R;
map < pair < int, int >, short > h;
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;
while(m--)
{
fin >> x >> y;
if(x != y) v[x].push(y), v[y].push(x);
else v[x].push(y), nr[x]++;
}
for(i = 1; i <= n; i++) if((v[i].size() - nr[i]) % 2 == 1) i = n + 1;
if(i == n + 2) fout << -1;
else
{
dfs(1);
fout << R.size() << '\n';
for(auto it:R) fout << it << ' ';
}
return 0;
}
void dfs(int nod)
{
int x;
while(v[nod].empty() == 0)
{
x = v[nod].front(), v[nod].pop();
if(x != nod)
{
h[{nod, x}]++, h[{x, nod}]--;
if(h[{nod, x}] > 0) dfs(x);
}
else dfs(x);
}
R.pb(nod);
}