Pagini recente » Cod sursa (job #1588173) | Cod sursa (job #724511) | Cod sursa (job #1496325) | Cod sursa (job #45202) | Cod sursa (job #2838588)
#include <bits/stdc++.h>
#define Dmax 100005
using namespace std;
ifstream f("in.in");
struct three{
int first,second; bool third;
};
vector < three > M;
vector < int > sol,G[Dmax];
stack < int > S;
int n,m;
bool EsteEuler()
{
for(int i = 1; i <= n; i++)
if(G[i].size() & 1)
return false;
return true;
}
int main()
{
f>>n>>m;
for(int i = 1; i <= m; i++)
{
int x,y;
f>>x>>y;
M.push_back(three{x,y,false});
G[x].push_back(i);
G[y].push_back(i);
}
if(!EsteEuler)
{
cout<<"-1\n";
return 0;
}
S.push(1);
while(!S.empty())
{
int nod = S.top();
if(G[nod].empty())
{
sol.push_back(nod);
S.pop();
}
else
{
int muchie = G[nod].back();
muchie--;
G[nod].pop_back();
if(!M[muchie].third)
{
M[muchie].third=true;
if(M[muchie].second == nod)
S.push(M[muchie].first);
else
S.push(M[muchie].second);
}
}
}
if(sol.size() == m+1)
{
for(unsigned int i = 0; i < sol.size() - 1; i++)
cout<<sol[i]<<" ";
}
else
{
cout<<"-1\n";
return 0;
}
return 0;
}