# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
604902 |
2022-07-25T10:43:06 Z |
valerikk |
Pipes (CEOI15_pipes) |
C++17 |
|
1276 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;
vector<int> g[N];
int tin[N], fup[N], 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:63:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4112 KB |
Output is correct |
2 |
Correct |
6 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
9308 KB |
Output is correct |
2 |
Correct |
107 ms |
8928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
14436 KB |
Output is correct |
2 |
Correct |
211 ms |
15324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
298 ms |
22952 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
435 ms |
34304 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
664 ms |
48308 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
909 ms |
61724 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1042 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1276 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |