Pagini recente » Cod sursa (job #2141686) | Cod sursa (job #757452) | Cod sursa (job #2161442) | Cod sursa (job #2311358) | Cod sursa (job #2806138)
#include <fstream>
#define M 500002
#define N 100002
#include <vector>
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
int n, m, v[M], nr;
bool viz[M];
struct bla
{
int ve, ord;
};
vector <bla> graph[N];
void euler(int nod)
{
while (graph[nod].size())
{
int vee = graph[nod].back().ve;
int mu = graph[nod].back().ord;
graph[nod].pop_back();
if (!viz[mu])
viz[mu] = 1, euler(vee);
}
v[++nr] = nod;
}
int main()
{
f >> n >> m;
int x, y;
for (int i = 1;i <= m;++i)
{
f >> x >> y;
graph[x].push_back({ y,i });
graph[y].push_back({ x,i });
}
for (int i = 1;i <= n;++i)
if (graph[i].size() % 2 != 0)
{
g << -1 << '\n';
f.close();
g.close();
return 0;
}
euler(1);
for (int i = 1;i < nr;++i) g << v[i] << ' ';
f.close();
g.close();
return 0;
}