# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
604940 |
2022-07-25T10:57:37 Z |
valerikk |
Pipes (CEOI15_pipes) |
C++17 |
|
1255 ms |
13064 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;
int mem[2 * N];
int *dsu1 = &mem[0];
int *dsu2 = &mem[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;
int ex[2 * N], es = 0;
vector<int> g[N];
int *tin = &mem[0];
int *fup = &mem[N];
int t = 0;
bool vis[N];
void dfs(int u, int pe = -1) {
vis[u] = true;
tin[u] = t++;
fup[u] = tin[u];
for (const int &e : g[u]) {
if (e == pe) continue;
int v = ex[e] ^ u;
if (!vis[v]) {
dfs(v, e);
fup[u] = min(fup[u], fup[v]);
if (fup[v] > tin[u]) {
printf("%d %d\n", u + 1, v + 1);
}
} else {
fup[u] = min(fup[u], tin[v]);
}
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
dsu1[i] = dsu2[i] = i;
}
for (int i = 0; i < m; ++i) {
int a, b;
scanf("%d%d", &a, &b);
--a, --b;
if (same1(a, b) && same2(a, b)) continue;
int e = es++;
g[a].push_back(e);
g[b].push_back(e);
ex[e] = a ^ b;
++e;
if (same1(a, b)) {
merge2(a, b);
} else {
merge1(a, b);
}
}
for (int i = 0; i < n; ++i) {
if (!vis[i]) {
dfs(i);
}
}
return 0;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:80:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2664 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3140 KB |
Output is correct |
2 |
Correct |
6 ms |
2864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
2972 KB |
Output is correct |
2 |
Correct |
111 ms |
2836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
226 ms |
3584 KB |
Output is correct |
2 |
Correct |
218 ms |
3188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
317 ms |
5128 KB |
Output is correct |
2 |
Correct |
247 ms |
4756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
418 ms |
9892 KB |
Output is correct |
2 |
Correct |
369 ms |
7076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
672 ms |
11000 KB |
Output is correct |
2 |
Correct |
616 ms |
8420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
835 ms |
13064 KB |
Output is correct |
2 |
Correct |
779 ms |
9068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1012 ms |
13060 KB |
Output is correct |
2 |
Correct |
973 ms |
8984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1255 ms |
12516 KB |
Output is correct |
2 |
Correct |
1190 ms |
9880 KB |
Output is correct |