Pagini recente » Cod sursa (job #902646) | Cod sursa (job #918886) | Cod sursa (job #1378938) | Cod sursa (job #2543455) | Cod sursa (job #2412570)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int nMax = 500005;
int N, M, len;
int st[nMax], dr[nMax];
bool viz[nMax];
vector <int> L[nMax];
int ans[nMax], poz[nMax];
inline void Read()
{
int x, y;
fin >> N >> M;
for(int i = 1; i <= M; i++)
{
fin >> x >> y;
st[i] = x;
dr[i] = y;
L[x].push_back(i);
L[y].push_back(i);
}
}
inline bool Euler()
{
for(int i = 1; i <= N; i++)
if(L[i].size() % 2)
return false;
return true;
}
inline void Dfs(int nod)
{
int k;
while(poz[nod] < L[nod].size())
{
k = L[nod][poz[nod]++];
if(!viz[k])
{
viz[k] = true;
Dfs(st[k] + dr[k] - nod);
}
}
ans[++len] = nod;
}
inline void Solve()
{
if(!Euler())
{
fout <<"-1\n";
return;
}
Dfs(1);
for(int i = 1; i <= len; i++)
fout << ans[i] << " ";
}
int main()
{
Read();
Solve();
return 0;
}