Pagini recente » Cod sursa (job #1698084) | Cod sursa (job #1962536) | Cod sursa (job #2178006) | Cod sursa (job #176587) | Cod sursa (job #1552842)
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#define nmax 100010
using namespace std;
int n,m,x,y;
vector <int> g[nmax],sol;
stack <int> st;
int main() {
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d %d",&n,&m);
for (int i=1;i<=m;i++) {
scanf("%d %d",&x,&y); g[x].push_back(y); g[y].push_back(x);
}
st.push(1);
while (!st.empty()) {
x=st.top();
if (g[x].size()==0) {
sol.push_back(x); st.pop(); continue;
}
int y=g[x][g[x].size()-1];
st.push(y); g[x].pop_back();
g[y].erase(find(g[y].begin(),g[y].end(),x));
}
for (int i=0;i<sol.size();i++) printf("%d ",sol[i]);
return 0;
}