# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
527354 |
2022-02-17T09:34:54 Z |
jamielim |
Pipes (CEOI15_pipes) |
C++14 |
|
1485 ms |
13172 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;
const int MAXN=100005;
int n,m;
int par[MAXN],par2[MAXN];
int root(int x){return par[x]=(par[x]==x?x:root(par[x]));}
int root2(int x){return par2[x]=(par2[x]==x?x:root2(par2[x]));}
vector<int> adj[MAXN]; // only stores at most 2*tree
bool vis[MAXN];
int low[MAXN];
int ctr=1;
void dfs(int x){
vis[x]=1;
par2[x]=low[x]=ctr++;
for(int i:adj[x]){
if(!vis[i]){
par[i]=x;
dfs(i);
if(low[i]>par2[x])printf("%d %d\n",x,i);
low[x]=min(low[x],low[i]);
}else if(i!=par[x])low[x]=min(low[x],par2[i]);
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)par[i]=par2[i]=i;
int a,b;
for(int i=0;i<m;i++){
scanf("%d%d",&a,&b);
//if a,b are in different trees, merge the two trees
int ra=root(a),rb=root(b);
if(ra!=rb){
par[ra]=rb;
adj[a].pb(b);
adj[b].pb(a);
continue;
}
//otherwise, take note that later we have to get rid of the entire cycle
int r2a=root2(a),r2b=root2(b);
if(r2a!=r2b){
par2[r2a]=par2[r2b];
adj[a].pb(b);
adj[b].pb(a);
}
}
memset(par,-1,sizeof(par));
memset(par2,-1,sizeof(par2));
memset(low,-1,sizeof(low));
for(int i=1;i<=n;i++)if(!vis[i])dfs(i);
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
pipes.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d%d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3788 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3788 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4304 KB |
Output is correct |
2 |
Incorrect |
7 ms |
4132 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
4564 KB |
Output is correct |
2 |
Incorrect |
108 ms |
4416 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
214 ms |
5428 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
361 ms |
6852 KB |
Output is correct |
2 |
Correct |
269 ms |
6252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
526 ms |
10240 KB |
Output is correct |
2 |
Incorrect |
385 ms |
7428 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
715 ms |
11204 KB |
Output is correct |
2 |
Incorrect |
670 ms |
8740 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
969 ms |
12936 KB |
Output is correct |
2 |
Incorrect |
892 ms |
8848 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1207 ms |
13172 KB |
Output is correct |
2 |
Incorrect |
1123 ms |
10484 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1485 ms |
12556 KB |
Output is correct |
2 |
Correct |
1304 ms |
9992 KB |
Output is correct |