#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using ll = long long;
const ll MAXN = 500005, MAXM = 500005;
vector<pair<ll, ll>> edges[MAXN];
bool seen[MAXM], vis[MAXN];
vector<ll> path;
void dfs(ll v) {
vis[v] = 1;
for (auto[u, id] : edges[v]) {
if (seen[id] || vis[u]) continue;
seen[id] = 1;
dfs(u);
}
path.push_back(v);
}
void solve() {
ll n, m;
cin >> n >> m;
for (ll i = 0; i < m; i++) {
ll v, u;
cin >> v >> u;
v--, u--;
edges[v].push_back({u, i});
edges[u].push_back({v, i});
}
for (ll v = 0; v < n; v++) {
memset(vis, 0, sizeof(vis));
path.clear();
dfs(v);
path.pop_back();
if (path.empty()) continue;
for (ll x : path) cout << x+1 << ' ';
cout << '\n';
}
}
int main() {
// freopen("promote.in", "r", stdin);
// freopen("promote.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |