Submission #1035143

# Submission time Handle Problem Language Result Execution time Memory
1035143 2024-07-26T05:15:34 Z vjudge1 Pipes (CEOI15_pipes) C++14
50 / 100
871 ms 65536 KB
    #include <iostream>
    #include <vector>
    #include <stdio.h>
    #include <algorithm>
     
    #define MAX_N 100000
     
    using namespace std;
     
    int N, M;
    vector<int> gp[MAX_N+1];
    int g1[MAX_N+1], g2[MAX_N+1];
    int up[MAX_N+1], lv[MAX_N+1], p[MAX_N+1];
     
    void init(){
    	for(int i=1; i<=N; i++)	g1[i] = g2[i] = i;
    }
     
    int find_g1(int x){
    	if(x==g1[x])	return x;
    	return g1[x] = find_g1(g1[x]);
    }
     
    int find_g2(int x){
    	if(x==g2[x])	return x;
    	return g2[x] = find_g2(g2[x]);
    }
     
    void union_g1(int x, int y){
    	x = find_g1(x); y = find_g1(y);
    	g1[x] = y;
    }
     
    void union_g2(int x, int y){
    	x = find_g2(x); y = find_g2(y);
    	g2[x] = y;
    }
     
    bool vst[MAX_N+1];
     
    void dfs(int x){
    	bool tf = true;
    	up[x] = lv[x];
    	vst[x] = true;
    	for(int i=0; i<gp[x].size(); i++){
    		if(gp[x][i]==p[x] && tf){
    			tf = false; continue;
    		}	
    		if(vst[gp[x][i]]){
    			up[x] = min(up[x], lv[gp[x][i]]);
    		}else{
    			p[gp[x][i]] = x;
    			lv[gp[x][i]] = lv[x]+1;
    			dfs(gp[x][i]);
    			if(up[gp[x][i]]>lv[x]){
    				printf("%d %d\n", gp[x][i], x);
    			}
    			up[x] = min(up[x], up[gp[x][i]]);
    		}
    	}
    }
     
    int main(){
    	scanf("%d %d", &N, &M);
    	init();
    	int a, b;
    	while(M--){
    		scanf("%d%d", &a, &b);
    		if(find_g1(a)!=find_g1(b)){
    			union_g1(a, b);
    			gp[a].push_back(b);
    			gp[b].push_back(a);
    		}
    		else if(find_g2(a)!=find_g2(b)){
    			union_g2(a, b);
    			gp[a].push_back(b);
    			gp[b].push_back(a);
    		}
    	}
    	for(int i=1; i<=N; i++){
    		if(!vst[i]){
    			lv[i] = 1;
    			dfs(i);
    		}
    	}
    	return 0;
    }

Compilation message

pipes.cpp: In function 'void dfs(int)':
pipes.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |      for(int i=0; i<gp[x].size(); i++){
      |                   ~^~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:64:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |      scanf("%d %d", &N, &M);
      |      ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:68:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |       scanf("%d%d", &a, &b);
      |       ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3160 KB Output is correct
2 Correct 3 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 2964 KB Output is correct
2 Correct 69 ms 2940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 3668 KB Output is correct
2 Correct 126 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 189 ms 5200 KB Output is correct
2 Correct 168 ms 15976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 303 ms 10324 KB Output is correct
2 Runtime error 260 ms 23560 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 429 ms 11348 KB Output is correct
2 Runtime error 491 ms 38608 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 550 ms 13396 KB Output is correct
2 Runtime error 548 ms 46088 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 728 ms 13400 KB Output is correct
2 Runtime error 767 ms 55968 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 816 ms 12940 KB Output is correct
2 Runtime error 871 ms 65536 KB Memory limit exceeded
3 Halted 0 ms 0 KB -