#include <bits/stdc++.h>
using namespace std;
constexpr int N = 5e5;
vector<int> g[N];
int vis[N];
set<int> path;
int dfs(int u) {
	path.insert(u);
	while (!g[u].empty()) {
		int v = g[u].back();
		g[v].erase(find(g[v].begin(), g[v].end(), u));
		g[u].pop_back();
		if (path.count(v)) {
			path.erase(u);
			cout << u + 1 << ' ';
			return v;
		}
		int r = dfs(v);
		if (r != u) {
			path.erase(u);
			cout << u + 1 << ' ';
			return r;
		}
		else cout << u + 1 << '\n';
	}
	return -1;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	while (m--) {
		int a, b;
		cin >> a >> b;
		g[--a].push_back(--b);
		g[b].push_back(a);
	}
	dfs(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... |