Pagini recente » Cod sursa (job #1200650) | Cod sursa (job #2976697) | Cod sursa (job #2665186) | Cod sursa (job #2756520) | Cod sursa (job #3329718)
#include <bits/stdc++.h>
using namespace std;
const int NMAX=1e5;
vector<int> ans;
int n, m;
unordered_multiset<int> s[NMAX+1];
///available edges
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("ciclueuler.in", "r", stdin);
freopen("ciclueuler.out", "w", stdout);
cin>>n>>m;
for(int i=1, x, y; i<=m; i++)
{
cin>>x>>y;
s[x].insert(y);
s[y].insert(x);
}
vector<int> st;
st.push_back(1);
while(!st.empty())
{
int nod=st.back();
if(s[nod].empty())
{
ans.push_back(nod);
st.pop_back();
}
else
{
int to=*(s[nod].begin());
s[nod].erase(s[nod].find(to));
s[to].erase(s[to].find(nod));
st.push_back(to);
}
}
int szans=ans.size();
for(int i=0; i<szans-1; i++)
cout<<ans[i]<<' ';
return 0;
}