Pagini recente » Cod sursa (job #2431665) | Cod sursa (job #891419) | Cod sursa (job #279293) | Cod sursa (job #2528475) | Cod sursa (job #2376101)
#include <bits/stdc++.h>
using namespace std;
#define nmax 100005
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
int n,m,grad[nmax];
bool sters[nmax*5];
struct str
{
int nod,indice;
};
vector<int>V;
vector<str>Q[nmax];
vector<int>edges;
void solve()
{
int indic=1;
while (!Q[indic].size())
{
++indic;
}
V.push_back(indic);
while (!V.empty())
{
int nod=V.back();
while (Q[nod].size()&&sters[Q[nod].back().indice])
{
Q[nod].pop_back();
}
if (Q[nod].size())
{
sters[Q[nod].back().indice]=true;
V.push_back(Q[nod].back().nod);
}
else
{
edges.push_back(nod);
V.pop_back();
}
}
int sz=edges.size()-1;
for (int i=0; i<sz; ++i)
g<<edges[i]<<' ';
}
void read()
{
f>>n>>m;
for (int i=1; i<=m; ++i)
{
int h1,h2;
f>>h1>>h2;
Q[h1].push_back({h2,i});
Q[h2].push_back({h1,i});
++grad[h1];
++grad[h2];
}
}
int main()
{
read();
bool grades=true;
for (int i=1; i<=n; ++i)
if (grad[i]%2!=0)
grades=false;
if (grades==true)
solve();
else
g<<-1;
return 0;
}