Pagini recente » Cod sursa (job #32602) | Cod sursa (job #2555906) | Cod sursa (job #2380024) | Cod sursa (job #87332) | Cod sursa (job #2823479)
#include <bits/stdc++.h>
#define DAU ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PLEC return 0;
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
#define cin fin
#define cout fout
#define N 500005
vector < vector < pair < int , int > > > g;
int v[N], f[N], st, dr, i, x, y, k, n, m, ind;
void fa(int nod)
{
for(auto t : g[nod])
{
if(f[t.second] == 0)
{
f[t.second] = 1;
fa(t.first);
}
}
v[++st] = nod;
}
int main()
{
DAU
cin >> n >> m;
g.resize(n+5);
for(int i = 1 ; i <= m ; i++)
{
cin >> x >> y;
g[x].push_back({y,i});
g[y].push_back({x,i});
}
for(int i = 1 ; i <= n ; i++)
{
if(g[i].size() % 2 == 1)
{
cout << -1;
PLEC
}
}
deque < int > c;
c.push_front(1);
while(!c.empty())
{
int nod = c.front();
if(g[nod].size() != 0)
{
int x = g[nod][g[nod].size()-1].second;
if(f[x] == 0)
{
f[x] = 1;
c.push_front(g[nod][g[nod].size()-1].first);
}
g[nod].pop_back();
}
else
{
v[++st] = nod;
c.pop_front();
}
}
for(int i = 1 ; i <= st ; i++)cout << v[i] << " ";
PLEC
}