This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int Z = 5e5;
int N, M;
vector<array<int, 2>> g[Z];
vector<int> o, s;
bool vis[Z];
void dfs(int u) {
while(!empty(g[u])) {
auto [v, i] = g[u].back();
g[u].pop_back();
if(!vis[i]) vis[i] = 1, dfs(v);
}
o.push_back(u);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> N >> M;
while(M--) {
int u, v; cin >> u >> v;
--u, --v;
g[u].push_back({v, M});
g[v].push_back({u, M});
}
dfs(0);
fill(vis, vis + N, 0);
for(int u : o) {
if(vis[u]) {
for(int v = -1; u != v; s.pop_back()) {
vis[v = s.back()] = 0;
cout << v + 1 << ' ';
}
cout << '\n';
}
s.push_back(u);
vis[u] = 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... |