Pagini recente » Cod sursa (job #875778) | Cod sursa (job #1156904) | Cod sursa (job #369906) | Cod sursa (job #1612228) | Cod sursa (job #2926086)
#include <fstream>
#include <vector>
#include <map>
using namespace std;
ifstream cin( "ciclueuler.in" );
ofstream cout( "ciclueuler.out" );
const int MAX = 100002;
map<pair<int, int>, bool> mp;
vector<int> noduri[ MAX ];
vector<int> rez;
int n, m, x, y;
void make( int nod ) {
rez.push_back( nod );
while( noduri[ nod ].size() ) {
int nn = noduri[ nod ].back();
noduri[ nod ].pop_back();
if( mp.count( make_pair( min( nod, nn ), max( nn, nod ) ) ) == 0 ) {
mp[ make_pair( min( nod, nn ), max( nn, nod ) ) ] = 1;
make( nn );
}
}
}
int main()
{
cin >> n >> m;
for( int i = 0; i < m; i++ ) {
cin >> x >> y;
noduri[ x ].push_back( y );
noduri[ y ].push_back( x );
}
bool ok = true;
for( int i = 1; i <= n; i++ )
if( noduri[ i ].size() & 1 )
ok = false;
if( ok == true ) {
make( 1 );
for( int i = 0; i < rez.size() - 1; i++ )
cout << rez[ i ] << ' ';
} else cout << "-1";
return 0;
}