# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
706726 |
2023-03-07T15:08:13 Z |
finn__ |
Pipes (CEOI15_pipes) |
C++17 |
|
1266 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
struct Dsu
{
vector<int> p;
Dsu(size_t n) { p = vector<int>(n, -1); }
int repr(int u) { return p[u] < 0 ? u : p[u] = repr(p[u]); }
bool merge(int i, int j)
{
i = repr(i);
j = repr(j);
if (i == j)
return 0;
if (p[i] > p[j])
swap(i, j);
p[i] += p[j];
p[j] = i;
return 1;
}
bool same_set(int i, int j) { return repr(i) == repr(j); }
int set_size(int i) { return -p[repr(i)]; }
};
constexpr size_t N = 200000;
unsigned y[N][2];
int compare_edges(void const *const a, void const *const b)
{
unsigned u = *(unsigned *)(a), v = *(unsigned *)(b);
return u == v ? 0 : (u < v ? -1 : 1);
}
int main()
{
size_t n, m, l = 0;
scanf("%zu %zu", &n, &m);
Dsu d1(n), d2(n);
while (m--)
{
unsigned u, v;
scanf("%u %u", &u, &v);
u--, v--;
if (d1.same_set(u, v))
d2.merge(u, v);
else
{
d1.merge(u, v);
y[l][0] = u;
y[l][1] = v;
l++;
y[l][0] = v;
y[l][1] = 1;
l++;
}
}
qsort(y, l, sizeof *y, compare_edges);
for (size_t i = 0; i < l; i++)
for (size_t j = i + 1; j < l && y[j][0] == y[i][0]; j++)
if (d2.same_set(y[i][1], y[j][1]))
d2.merge(y[i][0], y[i][1]);
for (size_t i = 0; i < l; i++)
if (!d2.same_set(y[i][0], y[i][1]) && y[i][0] < y[i][1])
printf("%u %u\n", y[i][0] + 1, y[i][1] + 1);
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%zu %zu", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~~~
pipes.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%u %u", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
596 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
5872 KB |
Output is correct |
2 |
Incorrect |
107 ms |
5732 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
190 ms |
10240 KB |
Output is correct |
2 |
Incorrect |
228 ms |
11904 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
293 ms |
17356 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
432 ms |
23688 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
621 ms |
36560 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
768 ms |
48092 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
992 ms |
59772 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1266 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |