# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
244655 |
2020-07-04T13:40:28 Z |
tqbfjotld |
Pipes (CEOI15_pipes) |
C++14 |
|
5000 ms |
7420 KB |
#include <vector>
#include <cstdio>
using namespace std;
#define MAXN 100005
bool isBridge[MAXN];
int p[MAXN];
int sz[MAXN];
int depth[MAXN];
vector<int> adjl[MAXN];
int p2[MAXN];
int rt[MAXN];
void dfs(int node, int parent){
for (int x : adjl[node]){
if (x==parent) continue;
depth[x] = depth[node]+1;
rt[x] = rt[node];
dfs(x,node);
if(p2[x]!=node){
isBridge[x] = isBridge[node];
p2[x] = node;
}
p[x] = node;
}
}
int func(int a, int b){
// printf("a: %d, depth: %d\n",a,depth[a]);
// printf("b: %d, depth: %d\n",b,depth[b]);
if (a==b) return a;
if (depth[b]<depth[a]) swap(a,b);
isBridge[b] = false;
int t = func(a,p[b]);
p[b] = t;
}
int n,e;
int main(){
//printf("%d\n",sizeof(isBridge)+sizeof(p)+sizeof(sz)+sizeof(depth)+sizeof(adjl)+sizeof(p2)+sizeof(rt));
scanf("%d%d",&n,&e);
for (int x = 0; x<=n; x++){
isBridge[x] = false;
p[x] = x;
sz[x] = 1;
depth[x] = 0;
rt[x] = x;
}
for (int x = 0; x<e; x++){
int a,b;
scanf("%d%d",&a,&b);
if (rt[a]==rt[b]){
func(a,b);
}
else{
if (sz[rt[b]]>sz[rt[b]]) swap(a,b);
sz[rt[a]] += sz[rt[b]];
adjl[b].push_back(a);
adjl[a].push_back(b);
depth[b] = depth[a]+1;
p2[b] = a;
p[b] = a;
// printf("p[%d] set to %d\n",b,a);
rt[b] = rt[a];
dfs(b,a);
isBridge[b] = true;
}
/*for (int x = 1; x<=n; x++){
printf("p[%d] = %d, depth %d, isbridge %d, p: %d\n",x,p2[x],depth[x],isBridge[x], p[x]);
}*/
}
for (int x = 1; x<=n; x++){
if (isBridge[x]){
printf("%d %d\n",x,p2[x]);
}
}
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:58:26: warning: self-comparison always evaluates to false [-Wtautological-compare]
if (sz[rt[b]]>sz[rt[b]]) swap(a,b);
~~~~~~~~~^~~~~~~~~~
pipes.cpp: In function 'int func(int, int)':
pipes.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
pipes.cpp: In function 'int main()':
pipes.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&e);
~~~~~^~~~~~~~~~~~~~
pipes.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
2944 KB |
Output is correct |
2 |
Correct |
31 ms |
2944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
2936 KB |
Output is correct |
2 |
Correct |
157 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
616 ms |
3448 KB |
Output is correct |
2 |
Correct |
365 ms |
3192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3126 ms |
4308 KB |
Output is correct |
2 |
Correct |
1841 ms |
4324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5055 ms |
6264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5073 ms |
6624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5088 ms |
7160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5072 ms |
7420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5064 ms |
7160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |