Pagini recente » Cod sursa (job #1180937) | Cod sursa (job #844820) | Cod sursa (job #1859874) | Cod sursa (job #1784990) | Cod sursa (job #2439727)
#include <bits/stdc++.h>
#define N 100005
using namespace std;
ifstream fin ("ciclueuler.in");
ofstream fout ("ciclueuler.out");
int n, x, y, m;
list <int> L[N];
vector <int> ciclu;
stack <int> st;
void Euler()
{
st.push(1);
while (!st.empty())
{
int nod = st.top();
if (L[nod].size() == 0)
{
ciclu.push_back(nod);
st.pop();
}
else
{
int nod2 = L[nod].front();
L[nod].pop_front();
L[nod2].erase(find(L[nod2].begin(), L[nod2].end(), nod));
st.push(nod2);
}
}
}
int main()
{
fin >> n >> m;
while (m--)
{
fin >> x >> y;
L[x].push_back(y);
L[y].push_back(x);
}
for (int i = 1; i <= n; i++)
{
if (L[i].size() % 2 == 1)
{
fout << -1;
return 0;
}
}
Euler();
for (auto &it : ciclu)
fout << it << " ";
return 0;
}