Pagini recente » Cod sursa (job #1524553) | Cod sursa (job #48594) | Cod sursa (job #2570336) | Cod sursa (job #1209591) | Cod sursa (job #2117554)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
#define lim 100010
int n,m,st[5*lim],dr,nod,act;
list <int> G[lim];
int main()
{
int x,y;
fin>>n>>m;
for (int i=1; i<=m; i++)
{
fin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
for (int i=1; i<=n; i++)
if (G[i].size()==0 || G[i].size()%2)
{
fout<<-1;
return 0;
}
st[++dr]=1;
while (dr)
{
nod=st[dr];
while (!G[nod].empty())
{
act = G[nod].front();
G[act].erase (find (G[act].begin(), G[act].end(), nod));
G[nod].pop_front();
st[++dr]=act;
nod=act;
}
fout<<st[dr--]<<' ';
}
fout.close();
return 0;
}