# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
604912 |
2022-07-25T10:47:40 Z |
valerikk |
Pipes (CEOI15_pipes) |
C++17 |
|
1201 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define all(a) begin(a), end(a)
#define sz(a) ((int) (a).size())
using ll = long long;
using ld = long double;
const int N = 1e5 + 7;
struct Dsu {
int dsu[N];
int get(int u) {
return dsu[u] == u ? u : dsu[u] = get(dsu[u]);
}
void merge(int u, int v) {
u = get(u);
v = get(v);
if (u != v) {
dsu[u] = v;
}
}
bool same(int u, int v) {
return get(u) == get(v);
}
Dsu() {
iota(all(dsu), 0);
}
} dsu1, dsu2;
int n, m;
list<int> g[N];
int *tin = &dsu1.dsu[0];
int *fup = &dsu2.dsu[0];
int t = 0;
bool vis[N];
void dfs(int u, int p = -1) {
vis[u] = true;
tin[u] = t++;
fup[u] = tin[u];
for (const int &v : g[u]) {
if (v == p) continue;
if (!vis[v]) {
dfs(v, u);
fup[u] = min(fup[u], fup[v]);
if (fup[v] > tin[u] && !dsu2.same(u, v)) {
printf("%d %d\n", u, v);
}
} else {
fup[u] = min(fup[u], tin[v]);
}
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) {
int a, b;
scanf("%d%d", &a, &b);
if (dsu1.same(a, b) && dsu2.same(a, b)) continue;
g[a].push_back(b);
g[b].push_back(a);
if (dsu1.same(a, b)) {
dsu2.merge(a, b);
} else {
dsu1.merge(a, b);
}
}
for (int i = 1; i <= n; ++i) {
if (!vis[i]) {
dfs(i);
}
}
return 0;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
42 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
43 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
4172 KB |
Output is correct |
2 |
Runtime error |
132 ms |
65536 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
214 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
305 ms |
8572 KB |
Output is correct |
2 |
Runtime error |
257 ms |
65536 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
407 ms |
18912 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
637 ms |
21236 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
829 ms |
25352 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1041 ms |
25356 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1201 ms |
24216 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |