Pagini recente » Cod sursa (job #2893398) | Cod sursa (job #2475520) | Cod sursa (job #1912459)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
const int nmax = 500005;
int N,M,st[nmax],dr[nmax],poz[nmax];
bool used[nmax];
vector < int > L[nmax],ans;
inline void Read()
{
int i,x,y;
fin >> N >> M;
for(i = 1; i <= M; i++)
{
fin >> st[i] >> dr[i];
L[st[i]].push_back(i);
L[dr[i]].push_back(i);
}
}
inline bool Euler()
{
for(int i = 1; i <= N; i++)
if(L[i].size() & 1) return false;
return true;
}
inline void DFS(int nod)
{
int x;
while(L[nod].size() > poz[nod])
{
x = L[nod][poz[nod]++];
if(!used[x])
{
used[x] = true;
DFS(st[x] + dr[x] - nod);
}
}
ans.push_back(nod);
}
int main()
{
Read();
if(!Euler()) fout << "-1\n";
else
{
DFS(1);
ans.pop_back();
for(auto it : ans) fout << it << " ";
fout << "\n";
}
fout.close();
return 0;
}