답안 #224119

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
224119 2020-04-17T08:22:50 Z kshitij_sodani Pipes (CEOI15_pipes) C++17
20 / 100
1734 ms 65540 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
int n,m;
int par[100001];
int par2[100001];
int find(int no){
	if(par[no]==no){
		return no;
	}
	par[no]=find(par[no]);
	return par[no];
}
int find2(int no){
	if(par2[no]==no){
		return no;
	}
	par2[no]=find2(par2[no]);
	return par2[no];
}
vector<int> adj[100001];
int cco=1;
map<pair<int,int>,int> kk;
void dfs(int no,int par3=-1){
	par[no]=cco;
	cco+=1;
	for(auto nn:adj[no]){
		if(par[nn]>0){
			if(nn==par3){
				continue;
			}
			if(par[nn]>=par[no]){
				continue;
			}
			par2[nn]-=1;
			par2[no]+=1;
		}
		else{
			dfs(nn,no);
			if(par2[nn]==0){
				if(kk[{no,nn}]==1){
					cout<<no+1<<" "<<nn+1<<endl;
				}
				
			}
			par2[no]+=par2[nn];
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m;
	for(int i=0;i<n;i++){
		par[i]=i;
		par2[i]=i;
	}
	int aa,bb;
	int cc,dd;
	int e,f;
	for(int i=0;i<m;i++){
		cin>>cc>>dd;
		cc-=1;
		dd-=1;
		
	//	adj[cc].pb(dd);
	//		adj[dd].pb(cc);
	//		continue;
		//cout<<cc<<" "<<dd<<endl;
		aa=find(cc);
	//	cout<<aa;
		bb=find(dd);
		if(kk[{cc,dd}]==1){
			kk[{cc,dd}]+=1;
			kk[{dd,cc}]+=1;

		}
	//	cout<<"::"<<bb<<endl;
		if(aa==bb){
			e=find2(cc);
			f=find2(dd);
			if(e==f){
				continue;
			}
			adj[cc].pb(dd);
			adj[dd].pb(cc);
			kk[{cc,dd}]+=1;
			kk[{dd,cc}]+=1;
			par2[e]=f;
		}
		else{
			par[aa]=bb;
			adj[cc].pb(dd);
			adj[dd].pb(cc);
			kk[{cc,dd}]+=1;
			kk[{dd,cc}]+=1;
		}

	//	cout<<cc<<",,,,,,,,"<<dd<<endl;
	}
	//vis=par
	//dp=par2
	for(int i=0;i<n;i++){
		par[i]=0;
		par2[i]=0;
	}
	for(int i=0;i<n;i++){
		if(par[i]==0){
			dfs(i);
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 4480 KB Output is correct
2 Correct 18 ms 4224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 788 ms 40160 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1533 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1301 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1511 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1611 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1575 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1734 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1726 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -