#include <bits/stdc++.h>
using namespace std;
#define fi first
#define pb push_back
#define eb emplace_back
#define se second
typedef long long ll;
using pii = pair<int, int>;
const int nmax = 1e6 + 5;
vector<pii> adj[nmax];
vector<int> path;
int deg[nmax], vis[nmax], n, m;
void dfs(int u) {
while (!adj[u].empty()) {
auto [son, idx] = adj[u].back();
adj[u].pop_back();
if (vis[idx])
continue;
vis[idx] = 1;
dfs(son);
}
path.pb(u);
deg[u]++;
if (deg[u] == 2) {
cout << u << ' ';
path.pop_back();
while (path.back() != u) {
cout << path.back() << ' ';
deg[path.back()]--;
path.pop_back();
}
cout << '\n';
deg[u] = 1;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int u, v, i = 1; i <= m; i++) {
cin >> u >> v;
adj[u].pb({v, i});
adj[v].pb({u, i});
}
dfs(1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |