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>
#define DEBUG 0
using namespace std;
const int MAX_N = 5e5 + 10;
set <int> graph[MAX_N];
bitset <MAX_N> visited;
bool dfs(int u, int x, int p) {
if(visited[u] == true) {
return u == x;
}
visited[u] = true;
for(auto v : graph[u]) {
if(v == p) {
continue;
}
if(dfs(v, x, u) == true) {
graph[u].erase(v);
graph[v].erase(u);
cout << u << ' ';
return true;
}
}
visited[u] = false;
return false;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
graph[u].insert(v);
graph[v].insert(u);
}
for(int i = 1; i <= n; i++) {
while(!graph[i].empty()) {
dfs(i, i, -1);
cout << '\n';
visited = 0;
}
}
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... |