Pagini recente » Cod sursa (job #1906593) | Cod sursa (job #2268699) | Cod sursa (job #1755203) | Cod sursa (job #2267504) | Cod sursa (job #2927992)
#include <algorithm>
#include <fstream>
#include <list>
using namespace std;
ifstream cin( "ciclueuler.in" );
ofstream cout( "ciclueuler.out" );
const int MAX = 1e5 + 10;
list<int> l[ MAX ];
int st[ MAX * 5 ];
int n, m, x, y;
int main()
{
cin >> n >> m;
for( int i = 1; i <= m; ++i ) {
cin >> x >> y;
l[ x ].push_back( y );
l[ y ].push_back( x );
}
bool ok = true;
for( int i = 1; i <= n; ++i )
if( l[ i ].size() & 1 )
ok = false;
if( ok ) {
int poz = 1;
st[ poz ] = 1;
while( poz > 0 ) {
x = st[ poz ];
while( !l[ x ].empty() ) {
y = l[ x ].back();
l[ x ].pop_back();
l[ y ].erase( find( l[ y ].begin(), l[ y ].end(), x ) );
st[ ++poz ] = y;
x = y;
}
cout << st[ poz-- ] << ' ';
}
cout << '\n';
} else cout << "-1\n";
return 0;
}