Pagini recente » Cod sursa (job #163931) | Istoria paginii runda/yu2/clasament | Cod sursa (job #1122746) | simulare-cartita-12 | Cod sursa (job #2836664)
#include <bits/stdc++.h>
#define Dmax 100005
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
int n,m;
vector < pair <int,int> > M;
vector < bool > elim;
vector < int > G[Dmax], L;
int main()
{
f>>n>>m;
int x,y;
while(f>>x>>y)
{
M.push_back(make_pair(x,y));
elim.push_back(false);
G[x].push_back(M.size()-1);
G[y].push_back(M.size()-1);
}
for(int i = 1; i <= n; i++)
if(G[i].size() & 1)
{
cout<<-1;
return 0;
}
stack <int> S;
S.push(1);
while(!S.empty())
{
int k = S.top();
if(!G[k].empty())
{
int x = G[k].back();
G[k].pop_back();
if(!elim[x])
{
elim[x] = true;
int p = M[x].second;
// if(p==k)
// p = M[x].first;
S.push(p);
}
}
else
{
L.push_back(k);
S.pop();
}
}
for(unsigned int i = 0 ; i<L.size(); i++)
g<<L[i]<<" ";
return 0;
}