답안 #4150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4150 2013-09-02T12:42:54 Z pys7293 Cactus? Not cactus? (kriii1_C) C++
1 / 1
76 ms 15104 KB
#include <algorithm>
#include <cstdio>
#include <map>
#include <memory.h>
#include <vector>

using namespace std;

int N, M;
int Lv[111111], C;
int Lo[111111];
int Chk[111111];
int P[111111];

vector<vector<int> > L;

void DFS(int i, int PP)
{
	if (Lv[i] == 0) Lv[i] = Lo[i] = ++C;
	for (int j = 0; j < L[i].size(); j++) {
		if (PP == L[i][j]) continue;
		if (Lv[L[i][j]] == 0) {
			P[L[i][j]] = i;
			DFS(L[i][j], i);
			Lo[i] = min(Lo[i], Lo[L[i][j]]);
			if (Lv[i] < Lo[L[i][j]]) Chk[L[i][j]] = true;
		} else Lo[i] = min(Lo[i], Lv[L[i][j]]);
	}
}

int main(void)
{
	scanf("%d%d", &N, &M);
	L.resize(N + 1);
	for (int i = 1; i <= M; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		L[u].push_back(v);
		L[v].push_back(u);
	}
	DFS(1, 0);
	bool Ans = true;
	for (int i = 1; i <= N; i++) {
		if (!Ans) break;
		int CC = 0;
		for (int j = 0; j < L[i].size(); j++) {
			if (i == P[L[i][j]] && Chk[L[i][j]]) continue;
			if (L[i][j] == P[i] && Chk[i]) continue;
			CC++;
		}
		if (!(CC == 0 || CC == 2)) Ans = false;
	}
	printf("%s\n", Ans ? "Cactus" : "Not cactus");

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2980 KB Output is correct
2 Correct 0 ms 2980 KB Output is correct
3 Correct 0 ms 3128 KB Output is correct
4 Correct 0 ms 3140 KB Output is correct
5 Correct 0 ms 3112 KB Output is correct
6 Correct 0 ms 3244 KB Output is correct
7 Correct 0 ms 3244 KB Output is correct
8 Correct 0 ms 3112 KB Output is correct
9 Correct 0 ms 3244 KB Output is correct
10 Correct 48 ms 7776 KB Output is correct
11 Correct 32 ms 7352 KB Output is correct
12 Correct 36 ms 10120 KB Output is correct
13 Correct 44 ms 8948 KB Output is correct
14 Correct 56 ms 8576 KB Output is correct
15 Correct 60 ms 11668 KB Output is correct
16 Correct 40 ms 8868 KB Output is correct
17 Correct 40 ms 10232 KB Output is correct
18 Correct 64 ms 13780 KB Output is correct
19 Correct 76 ms 15104 KB Output is correct
20 Correct 36 ms 9312 KB Output is correct
21 Correct 60 ms 9024 KB Output is correct
22 Correct 52 ms 12352 KB Output is correct
23 Correct 0 ms 2980 KB Output is correct
24 Correct 0 ms 2980 KB Output is correct
25 Correct 4 ms 3944 KB Output is correct
26 Correct 52 ms 7836 KB Output is correct
27 Correct 20 ms 4920 KB Output is correct
28 Correct 48 ms 7180 KB Output is correct
29 Correct 48 ms 7180 KB Output is correct
30 Correct 52 ms 7312 KB Output is correct
31 Correct 48 ms 7180 KB Output is correct
32 Correct 56 ms 7836 KB Output is correct
33 Correct 60 ms 7836 KB Output is correct
34 Correct 52 ms 7836 KB Output is correct