Pagini recente » Cod sursa (job #2182660) | Cod sursa (job #986377) | Cod sursa (job #1424959) | Cod sursa (job #1045774) | Cod sursa (job #2342274)
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
vector<int>G[100005];
stack<int>st;
void Euler(int node)
{
int other;
while(!G[node].empty())
{
st.push(node);
other=G[node].back();
G[node].pop_back();
G[other].erase(find(G[other].begin(),G[other].end(),node));
node=other;
}
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
int n,x,y,i,m,now;
bool ok;
scanf("%d%d",&n,&m);
for(i=1;i<=m;++i)
{
scanf("%d%d",&x,&y);
G[x].push_back(y);
G[y].push_back(x);
}
ok=1;
for(i=1;i<=n;++i)
{
if(G[i].size()&1)
{
ok=0;
break;
}
}
if(ok==0)
printf("-1\n");
else
{
now=1;
do
{
Euler(now);
now=st.top();
printf("%d ",now);
st.pop();
}
while(!st.empty());
}
return 0;
}