Pagini recente » Cod sursa (job #137932) | Cod sursa (job #1345930) | Cod sursa (job #395123) | Cod sursa (job #2331526) | Cod sursa (job #1915867)
#include <fstream>
#include <vector>
using namespace std;
ifstream in ("ciclueuler.in");
ofstream out ("ciclueuler.out");
const int NMAX = 100005;
const int MMAX = 500005;
vector <int> g[NMAX], stiva, sol;
bool folosit[MMAX];
int from[MMAX], to[MMAX];
int main()
{
int n, m, x, y, i;
in >> n >> m;
for(i = 1; i <= m; i++)
{
in >> x >> y;
g[x].push_back(i);
g[y].push_back(i);
from[i] = x;
to[i] = y;
}
for(i = 1; i <= n; i++)
if(g[i].size() %2 == 1)
{
out <<"-1";
return 0;
}
stiva.push_back(1);
while(!stiva.empty())
{
int nod = stiva.back();
if(!g[nod].empty())
{
int e = g[nod].back();
g[nod].pop_back();
if(folosit[e] == false)
{
folosit[e] = true;
int x = from[e];
if(x == nod)
x = to[e];
stiva.push_back(x);
}
}
else
{
stiva.pop_back();
sol.push_back(nod);
}
}
vector <int> :: iterator it;
for(it = sol.begin(); it < sol.end() -1; ++it)
out << *it << " ";
return 0;
}