Cod sursa(job #773580)

Utilizator legionarulCorneliu Zelea Codreanu legionarul Data 2 august 2012 06:48:38
Problema Ciclu Eulerian Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
 # include <fstream>
 # include <cstring>
 # include <algorithm>
 # include <vector>
 
 # define pb push_back
 # define dim 500005
 
 using namespace std;
 
 ifstream f("ciclueuler.in");
 ofstream g("ciclueuler.out");
 
 struct euler
 {
	 int nod, poz;
 };
 
 vector < euler > a[ dim ];
 bool viz[ dim ];
 
 int n, m;
 
 void citire()
 {
	 int i, x, y;
	 
	 f >> n >> m;
	 for ( i = 1 ; i <= m ; i++ )
	 {
		 f >> x >> y;
		 a[ x ].pb( ( euler ) { y, i } );
		 a[ y ].pb( ( euler ) { x, i } );
	 }
 }
 
 inline void df( int x )
 {
	 int i;
	 
	 for ( i = 0 ; i < a[ x ].size() ; i++ )
		 if ( viz[ a[ x ][ i ].poz ] == 0 )
		 {
			 viz[ a[ x ][ i ].poz ] = 1;
			 df( a[ x ][ i ].nod );
		 }
		 g << x << " ";
 }
 
 int main()
 {
	 int i;
	 citire();
	 for ( i = 1 ; i <= n ; i++ )
		 if( a[ i ].size() % 2 != 0 )
		 {
			 g << "-1";
			 return 0;
		 }
		 df( 1 );
	 return 0;
 }