Pagini recente » Cod sursa (job #1934418) | Cod sursa (job #482561) | Cod sursa (job #2028347) | Cod sursa (job #2935964) | Cod sursa (job #2560744)
#include <bits/stdc++.h>
using namespace std;
ifstream in("ciclueuler.in");
ofstream out("ciclueuler.out");
const int Nmax = 1e5 + 5;
bool vis[Nmax];
stack <int> S;
vector <int> G[Nmax], ans;
void dfs(int node) {
S.push(node);
while(!S.empty()) {
int x = S.top();
if(G[x].empty()) {
ans.push_back(x);
S.pop();
} else {
int y = G[x].back();
G[x].pop_back();
S.push(y);
G[y].erase(find(G[y].begin(),G[y].end(),x));
}
}
}
int main() {
int N,M;
in >> N >> M;
int x,y;
while(M--) {
in >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(1);
for(auto i : ans)
out << i << " ";
return 0;
}