Pagini recente » Cod sursa (job #2779317) | Cod sursa (job #611785) | Cod sursa (job #997916) | Cod sursa (job #3178896) | Cod sursa (job #2806137)
#include <fstream>
#include <vector>
#include <deque>
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
bool viz[500002];
struct bla
{
int no, mu;
};
vector <bla> graph[100002];
deque <int> q;
deque <int> ::reverse_iterator it;
void euler(int nod)
{
for (int i = 0;i < graph[nod].size();++i)
{
int ve = graph[nod][i].no;
if (!viz[graph[nod][i].mu])
{
viz[graph[nod][i].mu] = 1;
euler(ve);
}
}
q.push_back(nod);
}
int main()
{
int n, m, x, y;
f >> n >> m;
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;
return 0;
}
euler(1);
q.pop_front();
for (it = q.rbegin();it != q.rend();++it)
g << *it << ' ';
return 0;
}