답안 #5196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5196 2014-02-14T08:47:05 Z ainta 작은 사이클들 (YDX13_smallcycles) C++
1 / 1
76 ms 12908 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[100010];
int n, num[100001], cnt, par[100010], res;
bool chk[100010];
void DFS(int a){
	num[a] = ++cnt;
	int i, x, c = 0;
	for (i = 0; i < E[a].size(); i++){
		if (num[E[a][i]]){
			if (E[a][i] != par[a] && num[E[a][i]] < num[a]){
				x = a;
				while (x != E[a][i]){
					chk[x] = true;
					x = par[x];
				}
			}
			continue;
		}
		par[E[a][i]] = a;
		DFS(E[a][i]);
		if (!chk[E[a][i]])c++;
	}
	res += c / 2;
	if (c % 2 == 1 && !chk[a]){
		chk[a] = true;
		res++;
	}
}
int main()
{
	int i, m, a, b;
	scanf("%d%d", &n, &m);
	while (m--){
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
	}
	chk[1] = true;
	DFS(1);
	printf("%d\n", res);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4428 KB Output is correct
2 Correct 0 ms 4428 KB Output is correct
3 Correct 0 ms 4428 KB Output is correct
4 Correct 0 ms 4428 KB Output is correct
5 Correct 0 ms 4428 KB Output is correct
6 Correct 4 ms 4560 KB Output is correct
7 Correct 0 ms 4428 KB Output is correct
8 Correct 56 ms 7596 KB Output is correct
9 Correct 64 ms 7596 KB Output is correct
10 Correct 32 ms 6012 KB Output is correct
11 Correct 60 ms 7332 KB Output is correct
12 Correct 56 ms 7596 KB Output is correct
13 Correct 0 ms 4428 KB Output is correct
14 Correct 0 ms 4428 KB Output is correct
15 Correct 0 ms 4428 KB Output is correct
16 Correct 0 ms 4428 KB Output is correct
17 Correct 36 ms 7716 KB Output is correct
18 Correct 24 ms 7980 KB Output is correct
19 Correct 40 ms 7980 KB Output is correct
20 Correct 20 ms 6140 KB Output is correct
21 Correct 40 ms 7716 KB Output is correct
22 Correct 44 ms 7980 KB Output is correct
23 Correct 0 ms 4428 KB Output is correct
24 Correct 0 ms 4428 KB Output is correct
25 Correct 0 ms 4428 KB Output is correct
26 Correct 0 ms 4704 KB Output is correct
27 Correct 4 ms 4736 KB Output is correct
28 Correct 64 ms 11072 KB Output is correct
29 Correct 56 ms 11476 KB Output is correct
30 Correct 36 ms 7148 KB Output is correct
31 Correct 76 ms 11660 KB Output is correct
32 Correct 68 ms 12908 KB Output is correct
33 Correct 0 ms 4428 KB Output is correct
34 Correct 0 ms 4428 KB Output is correct
35 Correct 0 ms 4428 KB Output is correct
36 Correct 0 ms 4692 KB Output is correct
37 Correct 36 ms 7492 KB Output is correct
38 Correct 44 ms 8196 KB Output is correct
39 Correct 40 ms 8188 KB Output is correct
40 Correct 16 ms 6308 KB Output is correct
41 Correct 40 ms 7804 KB Output is correct
42 Correct 48 ms 8172 KB Output is correct
43 Correct 0 ms 4428 KB Output is correct
44 Correct 0 ms 4428 KB Output is correct
45 Correct 0 ms 4428 KB Output is correct
46 Correct 4 ms 4560 KB Output is correct
47 Correct 8 ms 5012 KB Output is correct
48 Correct 68 ms 7956 KB Output is correct
49 Correct 72 ms 8232 KB Output is correct
50 Correct 36 ms 6168 KB Output is correct
51 Correct 52 ms 8064 KB Output is correct
52 Correct 60 ms 8372 KB Output is correct