Pagini recente » Cod sursa (job #276976) | Cod sursa (job #263514) | Diferente pentru implica-te/arhiva-educationala intre reviziile 223 si 74 | Cod sursa (job #2440546) | Cod sursa (job #2238952)
#include<bits/stdc++.h>
using namespace std;
stack<int>st;
vector<int>G[100005];
vector<int>:: iterator it;
int can=1;
void fastboi(int x)
{
int other;
st.push(x);
if(G[x].size()==0)
{
while(st.size()>0&&G[st.top()].size()==0)
{
if(st.size()!=1) printf("%d ",st.top());
st.pop();
}
if(st.size()!=0) fastboi(st.top());
else return;
}
else
{
other=G[x].back();
G[x].pop_back();
it=find(G[other].begin(),G[other].end(),x);
G[other].erase(it);
fastboi(other);
}
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
int n,i,j,x,x1,m;
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++)
{
scanf("%d%d",&x,&x1);
G[x].push_back(x1);
G[x1].push_back(x);
}
fastboi(1);
while(st.size()>0)
{
if(st.size()!=1) printf("%d ",st.top());
st.pop();
}
}