Pagini recente » Cod sursa (job #1994725) | Cod sursa (job #337680) | Cod sursa (job #2018599) | Cod sursa (job #1972037) | Cod sursa (job #1649840)
#include <fstream>
#include <vector>
#include <stack>
#include <algorithm>
#include <cstring>
#include <bitset>
#define INF 0x3f3f3f3f
#define edge g[nod][g[nod].size() - 1]
using namespace std;
ifstream is("ciclueuler.in");
ofstream os("ciclueuler.out");
using VI = vector<int>;
using VVI = vector<VI>;
int n, m;
VI answ;
VVI g;
vector<pair<int, int>> e;
bitset<500001> ok;
void Read();
bool Check();
void Solve(int nod);
int main()
{
Read();
if ( !Check() )
os << "-1";
else
Solve(1);
is.close();
os.close();
return 0;
}
void Solve(int nod)
{
while ( g[nod].size() )
if ( ok[edge] )
g[nod].pop_back();
else
{
ok[edge] = true;
Solve(e[edge].first + e[edge].second - nod);
}
if ( answ.size() )
{
os << answ[0] << " ";
answ.pop_back();
}
answ.push_back(nod);
}
bool Check()
{
if ( m < n - 1 )
return false;
for ( int x = 1; x <= n; ++x )
if ( !g[x].size() || g[x].size() & 1 )
return false;
return true;
}
void Read()
{
is >> n >> m;
g = VVI(n + 1);
int x, y;
for ( int i = 0; i < m; ++i )
{
is >> x >> y;
g[x].push_back(i);
g[y].push_back(i);
e.push_back(make_pair(x, y));
}
}