Pagini recente » Cod sursa (job #284680) | Cod sursa (job #2372190) | Cod sursa (job #723990) | Cod sursa (job #2110544) | Cod sursa (job #2174095)
#include <fstream>
#include <vector>
using namespace std;
ifstream in ("ciclueuler.in");
ofstream out ("ciclueuler.out");
const int N = 100005;
const int M = 500005;
vector <int> g[N], s;
int from[M], to[M];
bool folosit[M];
int main()
{
int n, m, i, x, y;
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;
}
s.push_back(1);
int nod, muchie, vec;
while(!s.empty())
{
nod = s.back();
if(!g[nod].empty())
{
muchie = g[nod].back();
g[nod].pop_back();//!!!!
if(folosit[muchie] == false)
{
folosit[muchie] = true;
vec = to[muchie];
if(vec == nod)
vec = from[muchie];
s.push_back(vec);
}
}
else
{
s.pop_back();
if(!s.empty())
out << nod <<" ";
}
}
return 0;
}