답안 #396315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396315 2021-04-29T18:06:36 Z The_Blitz Pipes (CEOI15_pipes) C++17
80 / 100
1469 ms 65536 KB
// Restart
// += O(logn) ; + = O(n)
 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;

vector<int> G[100005];

int g_low[100005];
int g_num[100005];

int P[2][100005];
int n,m;
int cont = 1;

void dsu(int z){
	for(int i=1; i<=n;i++){
		P[z][i] = i;
	}
}
 
int dsu_find(int z, int x){
	if(x==P[z][x]) return x;
	P[z][x] = dsu_find(z,P[z][x]);
	return P[z][x];
}
 
bool dsu_uni(int z, int a , int b){
	int x = dsu_find(z,a);
	int y = dsu_find(z,b);
	if(x==y) return false;
	P[z][y] = x;
	G[a].push_back(b);
    G[b].push_back(a);
    return true;
} 


void dfs(int x ,int p = -1){ // p: parent
    g_low[x]=g_num[x]=cont++; // low:component ; num:visit order

    for(int v : G[x]){
        if(g_num[v]==-1){
			
			dfs(v,x);
			/*if(g_low[v] >= g_num[x]){ // CUT-VERTEX
				//cut[x] = true;
			}*/
			
			if(g_low[v] > g_num[x] && dsu_find(1,v) != dsu_find(1,x)){ // BRIDGE
				//bridge.push_back({min(x,v),max(x,v)});
				cout<< x << " " << v << "\n";
			}
			g_low[x]=min(g_low[x],g_low[v]);
		}
        if(v != p){
			g_low[x]=min(g_low[x],g_num[v]);
		}
    }
	
}



void go(){
	cin>>n>>m;
	
	for(int i=1;i<=n;i++){
		g_low[i] = -1; g_num[i] = -1;
		P[0][i] = i; P[1][i] = i;
	}

	for(int i=1;i<=m;i++){
		int x,y; cin>>x>>y;
		if(!dsu_uni(0,x,y)){
			dsu_uni(1,x,y);
		}
	}

	for(int i=1;i<=n;i++){
		if(g_num[i] == -1) dfs(i);
	}

}


void timer(){
	clock_t begin = clock();
	go();
	clock_t end = clock();
	double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
	printf("%lf\n",time_spent);
}	

 
int main() {
  fastio;
  go();
  //timer();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3020 KB Output is correct
2 Correct 6 ms 2892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 2988 KB Output is correct
2 Correct 114 ms 2868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 3596 KB Output is correct
2 Correct 224 ms 3204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 317 ms 5012 KB Output is correct
2 Correct 289 ms 4852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 493 ms 9908 KB Output is correct
2 Correct 406 ms 6980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 705 ms 11008 KB Output is correct
2 Correct 718 ms 8476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 933 ms 12944 KB Output is correct
2 Correct 881 ms 8880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1129 ms 12980 KB Output is correct
2 Runtime error 1094 ms 62060 KB Memory limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 1331 ms 12376 KB Output is correct
2 Runtime error 1469 ms 65536 KB Memory limit exceeded