Cod sursa(job #1868227)

Utilizator loghin.alexandruLoghin Alexandru loghin.alexandru Data 4 februarie 2017 18:21:36
Problema Ciclu Eulerian Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#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;
}