Pagini recente » Cod sursa (job #514463) | Cod sursa (job #761150) | Cod sursa (job #1717083) | Cod sursa (job #1564340) | Cod sursa (job #456603)
Cod sursa(job #456603)
/*
* File: main.cpp
* Author: virtualdemon
*
* Created on May 16, 2010, 9:06 AM
*/
#include <list>
#include <cstdlib>
#include <fstream>
#include <iterator>
#include <algorithm>
#define Nmax 100011
/*
*
*/
using namespace std;
int j, w;
int d[Nmax];
bool uz[Nmax];
list< int > S, euler;
list< int > G[Nmax];
list< int >::const_iterator it, iend;
inline void dfs( int x )
{
while( !G[x].empty() )
{
w=*G[x].begin();
if( !uz[w] )
++j, uz[w]=true;
G[x].pop_front();
G[w].erase( find( G[w].begin(), G[w].end(), x ) );
S.push_back(x);
x=w;
}
}
int main( void )
{
int N, M, x, y, par, imp;
ifstream in( "ciclueuler.in" );
ofstream out( "ciclueuler.out" );
in>>N>>M;
par=N; imp=0;
for( ; M; --M )
{
in>>x>>y;
G[x].push_front(y);
G[y].push_front(x);
++d[x]; ++d[y];
}
for( x=1; x <= N; ++x )
if( d[x]%2 )
{
out<<"-1\n";
return EXIT_SUCCESS;
}
x=1;
do
{
dfs( x );
x=S.back(); S.pop_back();
euler.push_back(x);
}while( !S.empty() );
if( N != j )
out<<"-1";
else copy( euler.rbegin(), euler.rend(), ostream_iterator<int>( out, " " ) );
out<<'\n';
return EXIT_SUCCESS;
}