Submission #527346

# Submission time Handle Problem Language Result Execution time Memory
527346 2022-02-17T09:19:30 Z jamielim Pipes (CEOI15_pipes) C++14
10 / 100
1357 ms 26432 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

int p[MAXN],low[MAXN],dep[MAXN];
int ctr=1;
void dfs(int x){
	dep[x]=low[x]=ctr++;
	for(int i:adj[x]){
		if(dep[i]==0){
			p[i]=x;
			dfs(i);
			if(low[i]>dep[x])printf("%d %d\n",x,i);
			low[x]=min(low[x],low[i]);
		}else if(i!=p[x])low[x]=min(low[x],dep[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);
		}
	}
	
	for(int i=1;i<=n;i++)if(dep[i]==0)dfs(i);
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
pipes.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d%d",&a,&b);
      |   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Incorrect 2 ms 2672 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3148 KB Output is correct
2 Incorrect 5 ms 3020 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 109 ms 3340 KB Output is correct
2 Incorrect 108 ms 3152 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 193 ms 4068 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 319 ms 5704 KB Output is correct
2 Correct 267 ms 5344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 439 ms 10468 KB Output is correct
2 Incorrect 396 ms 7540 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 688 ms 11496 KB Output is correct
2 Incorrect 639 ms 9108 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 910 ms 13624 KB Output is correct
2 Incorrect 860 ms 10568 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1107 ms 13808 KB Output is correct
2 Incorrect 1080 ms 10920 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1357 ms 13480 KB Output is correct
2 Runtime error 1278 ms 26432 KB Memory limit exceeded
3 Halted 0 ms 0 KB -