답안 #54795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54795 2018-07-05T05:48:04 Z 김세빈(#1509) Pipes (CEOI15_pipes) C++11
30 / 100
3149 ms 65536 KB
#include <bits/stdc++.h>

using namespace std;

vector <int> V[101010];
int K[101010], T[101010];
bool chk[101010];
int n, m, cnt;

void dfs(int p)
{
	K[p] = ++cnt;
	
	for(auto t: V[p]){
		if(!K[t]) dfs(t);
	}
}

int dfs2(int p, int r)
{
	int ret, k, f;
	
	chk[p] = 1;
	f = 0;
	ret = k = K[p];
	
	for(auto t: V[p]){
		if(!chk[t]) ret = min(ret, dfs2(t, p));
		else if(t == r){
			if(f++) ret = min(ret, K[t]);
		}
		else ret = min(ret, K[t]);
	}
	
	if(ret == k && r != 0) printf("%d %d\n", p, r);
	
	return K[p] = ret;
}

int main()
{
	int i, a, b;
	
	scanf("%d%d", &n, &m);
	
	for(i=1;i<=m;i++){
		scanf("%d%d", &a, &b);
		V[a].push_back(b);
		V[b].push_back(a);
	}
	
	for(i=1;i<=n;i++){
		if(!K[i]) dfs(i);
	}
	
	for(i=1;i<=n;i++){
		if(!chk[i]) dfs2(i, 0);
	}
	
	return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  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]
   scanf("%d%d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3200 KB Output is correct
2 Correct 8 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 10780 KB Output is correct
2 Correct 168 ms 10196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 14288 KB Output is correct
2 Runtime error 383 ms 18552 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 678 ms 25044 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 1065 ms 30280 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 1863 ms 51840 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 2458 ms 65476 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 3048 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 3149 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -