#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int MAX_N = 5e5 + 10;
set <pair <int, int>> graph[MAX_N];
bool dfs(int u, int x, int p) {
if(u == x and p != -1) {
return true;
}
for(auto [v, i] : graph[u]) {
if(v == p) {
continue;
}
if(dfs(v, x, u) == true) {
graph[u].erase(make_pair(v, i));
graph[v].erase(make_pair(u, i));
cout << u << ' ';
return true;
}
}
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].emplace(v, i);
graph[v].emplace(u, i);
}
for(int i = 1; i <= n; i++) {
while(!graph[i].empty()) {
dfs(i, i, -1);
cout << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23764 KB |
Output is correct |
2 |
Execution timed out |
1094 ms |
39864 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Execution timed out |
1090 ms |
40084 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23764 KB |
Output is correct |
2 |
Execution timed out |
1077 ms |
40008 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |