Pagini recente » Cod sursa (job #300507) | Clasament oni2008 | Cod sursa (job #729782) | Cod sursa (job #3218500) | Cod sursa (job #1868227)
#include <iostream>
#include <fstream>
std::ifstream fin("ciclueuler.in");
std::ofstream fout("ciclueuler.out");
struct nod
{
int info;
nod* next;
};
nod* nodes[100000] = {};
void addList(nod*& start,int info)
{
if (start==nullptr)
{
start = new nod;
start->info = info;
start->next = nullptr;
}
else
{
nod*p = start;
while (p->next!=nullptr)
{
p = p->next;
}
nod* aux = new nod;
aux->info = info;
aux->next = nullptr;
p->next = aux;
}
}
void sterge(nod*& start,int i)
{
if (start!=nullptr)
{
nod*p = start;
start = start->next;
delete p;
nodes[i] = start;
}
}
int vecin=1;
void checkEuler(nod* start,int i)
{
while (nodes[i]!=nullptr)
{
vecin = nodes[i]->info;
sterge(nodes[i], i);
checkEuler(nodes[vecin], vecin);
}
fout << i << ' ';
}
int main()
{
int n, m;
fin >> n >> m;
for (unsigned int i = 0; i < m; i++)
{
int x, y;
fin >> x >> y;
addList(nodes[x], y);
addList(nodes[y], x);
}
checkEuler(nodes[1],1);
return 0;
}