Pagini recente » Cod sursa (job #3215684) | Cod sursa (job #2576003) | Cod sursa (job #80899) | Cod sursa (job #1961905) | Cod sursa (job #2165516)
#include <fstream>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
struct nod
{
int x;
nod*urm;
};
typedef nod* lista;
void ins(lista &L, int nr);
void del(lista &L, int nr);
int n, m, vf, S[500005];
lista L[100005];
int main()
{
int i, aux, x, y;
fin >> n >> m;
for (i=1;i<=m;i++)
{
fin >> x >> y;
ins(L[x],y);
ins(L[y],x);
}
S[++vf] = 1;
while (vf)
{
aux = S[vf];
if (L[aux])
{
S[++vf] = L[aux]->x;
del(L[L[aux]->x],aux);
del(L[aux],L[aux]->x);
}
else
{
if (vf > 1)
fout << aux << ' ';
vf--;
}
}
return 0;
}
void ins(lista &L, int nr)
{
nod *p = new nod;
p->x = nr;
p->urm = L;
L = p;
}
void del(lista &L, int nr)
{
nod *p, *q;
if (L->x == nr)
{
p = L;
L = L->urm;
delete p;
}
else
{
p = L;
q = p->urm;
while (q->x != nr)
{
p = p->urm;
q = q->urm;
}
p->urm = q->urm;
delete q;
}
}