#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m; cin >> n >> m;
int x, y;
vector<set<int>> adj(n);
for (int i = 0; i < m; i++) {
cin >> x >> y; x--; y--;
adj[x].insert(y);
adj[y].insert(x);
}
// hierholzer
vector<int> ans;
stack<int> sta;
sta.push(0);
while (sta.size()) {
int node = sta.top();
if (adj[node].size()) {
int next = *adj[node].begin();
adj[next].erase(node);
adj[node].erase(next);
sta.push(next);
} else {
sta.pop();
ans.push_back(node);
}
}
for (int i = 0; i < ans.size()-1; i++) {
cout << ans[i]+1 << " ";
}
cout << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |