Pagini recente » Cod sursa (job #2722372) | Cod sursa (job #2810179) | Cod sursa (job #1279874) | Cod sursa (job #2648844) | Cod sursa (job #1904876)
#include <bits/stdc++.h>
using namespace std;
vector <int> G[100005];
stack <int> S;
vector <int> ::iterator it;
bool OK=true;
int n,m,i,x,y,node;
void euler(int node)
{
int i,son;
while (G[node].size())
{
S.push(node);
son=G[node].back();
G[node].pop_back();
it=find(G[son].begin(),G[son].end(),node);
G[son].erase(it);
node=son;
}
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
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);
}
for (i=1; i<=n; i++) if (G[i].size()%2==1)
{
printf("-1\n");
return 0;
}
node=1;
while (!S.empty() || OK)
{
OK=false;
printf("%d ",node);
euler(node);
node=S.top();
S.pop();
}
return 0;
}