Pagini recente » Cod sursa (job #2025478) | Cod sursa (job #798232) | Cod sursa (job #2758664) | Cod sursa (job #2364757) | Cod sursa (job #2238956)
#include <cstdio>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
stack<int>st;
vector<int>G[100005];
vector<int>::iterator it;
void euler(int nod)
{
int other,ok,topu;
while(G[nod].size())
{
other=G[nod].back();
G[nod].pop_back();
it=find(G[other].begin(),G[other].end(),nod);
G[other].erase(it);
nod=other;
}
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
int n,m,i,j,x,y,nod;
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);
}
printf("1 ");
nod=1;
do
{
euler(nod);
x=st.top();
printf("%d ",x);
st.pop();
}while(!st.empty());
return 0;
}