Pagini recente » Cod sursa (job #2072286) | Cod sursa (job #1647899) | Cod sursa (job #1329739) | Cod sursa (job #107773) | Cod sursa (job #1758680)
#include <fstream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
#define MaxN 100001
vector<int> G[MaxN], ans;
stack<int> st;
int n, m, x, y;
int main() {
fin >> n >> m;
for ( int i = 1; i <= m; ++i ) {
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
st.push(1);
while(!st.empty()) {
int x = st.top();
if ( G[x].size() ) {
int y = G[x].back();
G[x].pop_back();
G[y].erase(find(G[y].begin(), G[y].end(), x));
st.push(y);
}
else {
ans.push_back(x);
st.pop();
}
}
for ( int i = 0; i < ans.size() - 1; ++i )
fout << ans[i] << ' ';
fin.close();
fout.close();
return 0;
}