# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
604919 |
2022-07-25T10:50:25 Z |
valerikk |
Pipes (CEOI15_pipes) |
C++17 |
|
1111 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;
int dsu1[N], dsu2[N];
int get1(int u) {
return dsu1[u] == u ? u : dsu1[u] = get1(dsu1[u]);
}
int get2(int u) {
return dsu2[u] == u ? u : dsu2[u] = get2(dsu2[u]);
}
void merge1(int u, int v) {
u = get1(u);
v = get1(v);
if (u != v) {
dsu1[u] = v;
}
}
void merge2(int u, int v) {
u = get2(u);
v = get2(v);
if (u != v) {
dsu2[u] = v;
}
}
bool same1(int u, int v) {
return get1(u) == get1(v);
}
bool same2(int u, int v) {
return get2(u) == get2(v);
}
int n, m;
vector<int> g[N];
int *tin = &dsu1[0];
int *fup = &dsu2[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] && !same2(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 (same1(a, b) && same2(a, b)) continue;
g[a].push_back(b);
g[b].push_back(a);
if (same1(a, b)) {
merge2(a, b);
} else {
merge1(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:75:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
2644 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
96 ms |
2668 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
2712 KB |
Output is correct |
2 |
Incorrect |
236 ms |
2708 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
260 ms |
2824 KB |
Output is correct |
2 |
Incorrect |
227 ms |
2868 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
325 ms |
3184 KB |
Output is correct |
2 |
Runtime error |
303 ms |
21492 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
558 ms |
3264 KB |
Output is correct |
2 |
Runtime error |
616 ms |
36712 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
758 ms |
3412 KB |
Output is correct |
2 |
Runtime error |
717 ms |
44836 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
858 ms |
3412 KB |
Output is correct |
2 |
Runtime error |
855 ms |
56460 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1033 ms |
3376 KB |
Output is correct |
2 |
Runtime error |
1111 ms |
65536 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |