Pagini recente » Cod sursa (job #599381) | Cod sursa (job #2547334) | Cod sursa (job #575381) | Cod sursa (job #980451) | Cod sursa (job #3167801)
#include <bits/stdc++.h>
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
const int mmax = 500005;
const int nmax = 100005;
struct muchii
{
int st, dr, ind;
};
vector<muchii> A[mmax];
vector<int> Q;
int n, m, fr[nmax];
static inline void euler(int x)
{
while(A[x].size())
{
muchii k = A[x].back();
A[x].pop_back();
if(!fr[k.ind])
{
fr[k.ind] = 1;
euler(k.dr);
}
}
Q.push_back(x);
}
int main()
{
f.tie();
f >> n >> m;
for(int i = 1; i <= m; i ++)
{
int x, y;
f >> x >> y;
A[x].push_back({x, y, i});
A[y].push_back({y, x, i});
}
for(int i = 1; i <= n; i ++)
if(A[i].size() % 2 == 1)
{
g << -1;
return 0;
}
euler(1);
for(int i = 0; i < Q.size() - 1; i ++)
g << Q[i] << " ";
return 0;
}