# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54971 |
2018-07-05T15:20:45 Z |
kdh9949 |
Pipes (CEOI15_pipes) |
C++17 |
|
1482 ms |
8952 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001, H = 17;
int n, m, p[N], P[N], c[N], d[N], s[N];
vector<int> e[N];
int f(int x){ return p[x] = (x == p[x] ? x : f(p[x])); }
int F(int x){ return P[x] = (x == P[x] ? x : F(P[x])); }
void g(int x, int y, int z){
s[x] = y; d[x] = z;
for(int i : e[x]) if(i != y) g(i, x, z + 1);
}
int main(){
scanf("%d%d", &n, &m);
iota(p, p + n + 1, 0);
iota(P, P + n + 1, 0);
iota(s, s + n + 1, 0);
fill(c + 1, c + n + 1, 1);
for(int x, y; m--; ){
scanf("%d%d", &x, &y);
if(f(x) != f(y)){
if(c[f(x)] < c[f(y)]) swap(x, y);
e[x].push_back(y); e[y].push_back(x);
g(y, x, d[x] + 1);
c[f(x)] += c[f(y)]; p[f(y)] = f(x);
}
else{
x = F(x); y = F(y);/*
while(x != y){
if(d[x] > d[y]){ P[x] = F(P[s[x]]); x = F(x); }
else{ P[y] = F(P[s[y]]); y = F(y); }
}*/
}
}
for(int i = 1; i <= n; i++) if(P[i] == i && s[i] != i) printf("%d %d\n", i, s[i]);
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2688 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
2944 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
113 ms |
2936 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
197 ms |
3212 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
336 ms |
4188 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
556 ms |
7060 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
695 ms |
7644 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
901 ms |
8952 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1229 ms |
8924 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1482 ms |
8580 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |