Cod sursa(job #795891)

Utilizator tibi9876Marin Tiberiu tibi9876 Data 9 octombrie 2012 20:30:07
Problema Ciclu Eulerian Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include<fstream>
#include<vector>
using namespace std;

vector <int> a[100001];
struct muchie 
{
	int x,y;
	bool z;
};
muchie v[500001];
int i,n,x,y,m;

ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");

void df(int x)
{
	while (++a[x][0]<a[x].size())
	{
		int k=a[x][a[x][0]];
		if (v[k].z==0)
		{
			v[k].z=1;
			df(v[k].x+v[k].y-x);
		}
	}
	g << x << ' ';
}		

void df2(int x)
{
	while (++a[x][0]<a[x].size())
	{
		int k=a[x][a[x][0]];
		if (v[k].z==0)
		{
			v[k].z=1;
			df(v[k].x+v[k].y-x);
		}
	}
}		
	
int main()
{
	f >> n >> m;
	for (i=1;i<=n;i++)
		a[i].push_back(0);
	for (i=1;i<=m;i++)
	{
		f >> x >> y;
		v[i].x=x;v[i].y=y;
		a[x].push_back(i);
		a[y].push_back(i);
	}
	for (i=1;i<=n;i++)
		if (a[i].size()%2==0)
		{
			g << -1;
			return 0;
		}
	df2(1);
	return 0;
}