답안 #311489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
311489 2020-10-10T13:08:50 Z Kenzo_1114 Pipes (CEOI15_pipes) C++17
30 / 100
2972 ms 65540 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100001;

int n, m, low[MAXN], depth[MAXN];
vector<int> graph[MAXN];

void dfs(int v, int p)
{
	depth[v] = (v == p) ? 0 : depth[p] + 1;
	low[v] = depth[v];

	bool first = false;
	for(int i = 0; i < graph[v].size(); i++)
	{
		int u = graph[v][i];
		
		if(low[u] >= 0)
		{
			if(u != p || first)	low[v] = min(low[v], depth[u]);
			if(u == p)	first = true;
			continue;	
		}

		dfs(u, v);
		low[v] = min(low[v], low[u]);

		if(low[u] > depth[v])	printf("%d %d\n", u, v);
	}
}

int main ()
{
	scanf("%d %d", &n, &m);

	for(int i = 1; i <= n; i++)	low[i] = -1;

	for(int i = 0, u, v; i < m; i++)
	{
		scanf("%d %d", &u, &v);
		graph[u].push_back(v);
		graph[v].push_back(u);
	}

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

/*

10 11
1 7
1 8
1 6
2 8
6 7
5 8
2 5
2 3
2 4
3 4
10 9


*/

Compilation message

pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:14:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i = 0; i < graph[v].size(); i++)
      |                 ~~^~~~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3220 KB Output is correct
2 Correct 7 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 16252 KB Output is correct
2 Correct 181 ms 15480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 352 ms 23924 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 680 ms 41336 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1020 ms 31460 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1683 ms 53468 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2206 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 2677 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 2972 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -