# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
706727 |
2023-03-07T15:10:27 Z |
finn__ |
Pipes (CEOI15_pipes) |
C++17 |
|
1196 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] = u;
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 |
1 ms |
212 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
468 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
5060 KB |
Output is correct |
2 |
Correct |
111 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
5372 KB |
Output is correct |
2 |
Correct |
221 ms |
5368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
306 ms |
5828 KB |
Output is correct |
2 |
Incorrect |
278 ms |
15340 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
3100 KB |
Output is correct |
2 |
Runtime error |
327 ms |
21212 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
578 ms |
3616 KB |
Output is correct |
2 |
Runtime error |
594 ms |
36640 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
749 ms |
4452 KB |
Output is correct |
2 |
Runtime error |
781 ms |
45560 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
944 ms |
4588 KB |
Output is correct |
2 |
Runtime error |
981 ms |
56984 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1196 ms |
11740 KB |
Output is correct |
2 |
Runtime error |
1192 ms |
65536 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |