Pagini recente » Cod sursa (job #1972026) | Cod sursa (job #2350138) | Cod sursa (job #1197376) | Cod sursa (job #2226629) | Cod sursa (job #1098571)
#include <fstream>
#include <vector>
#include <bitset>
#define Nmax 100099
#define Mmax 500099
#define pb push_back
#define x first
#define y second
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
int N,M;
vector < int > G[Mmax],sol;
bitset < Mmax > viz;
typedef pair<int,int> edge;
edge E[Mmax];
void ReadInput()
{
f>>N>>M;
for(int i=1;i<=M;++i)
{
f>>E[i].x>>E[i].y;
G[E[i].x].pb(i) , G[E[i].y].pb(i);
}
}
void Euler(int node)
{
for(vector<int>::iterator it=G[node].begin();it!=G[node].end();++it)
if(!viz[*it])
{
viz[*it]=1;
Euler(E[*it].x+E[*it].y-node);
}
sol.pb(node);
}
inline bool Eulerian()
{
for(int i=1;i<=N;++i)
if(G[i].size() % 2==1)return 0;
return 1;
}
int main()
{
ReadInput();
if(!Eulerian){ g<<"-1\n"; return 0;}
Euler(1);
for(vector<int>::iterator it=sol.begin();it!=sol.end();++it)
g<<*it<<' ';
g<<'\n';
return 0;
}