Submission #5125

# Submission time Handle Problem Language Result Execution time Memory
5125 2014-02-10T04:20:05 Z ainta Cactus? Not cactus? (kriii1_C) C++
0 / 1
92 ms 10088 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int par[100010], C, chk[100010];
vector<int>E[100010];
bool v[100010];
int n;
void DFS(int a){
	v[a] = true;
	int i, x;
	for (i = 0; i < E[a].size(); i++){
		if (v[E[a][i]] && E[a][i] != par[a]){
			x = a;
			while (x != E[a][i]){
				chk[x]++;
				x = par[x];
			}
			chk[x]++;
		}
	}
	for (i = 0; i < E[a].size(); i++){
		if (!v[E[a][i]]){
			par[E[a][i]] = a;
			DFS(E[a][i]);
		}
	}
}
int main(){
	int i, a, b, m;
	scanf("%d%d", &n, &m);
	while (m--){
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
	}
	DFS(1);
	for (i = 1; i <= n; i++)if (chk[i] >= 2)break;
	printf(i != n + 1 ? "Not Cactus\n" : "Cactus\n");
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4428 KB Output is correct
2 Correct 0 ms 4428 KB Output is correct
3 Correct 4 ms 4560 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 4 ms 4560 KB Output is correct
8 Correct 4 ms 4560 KB Output is correct
9 Correct 4 ms 4560 KB Output is correct
10 Correct 44 ms 7332 KB Output is correct
11 Correct 28 ms 7180 KB Output is correct
12 Correct 36 ms 7732 KB Output is correct
13 Correct 52 ms 7360 KB Output is correct
14 Correct 52 ms 7188 KB Output is correct
15 Correct 64 ms 8524 KB Output is correct
16 Correct 44 ms 7228 KB Output is correct
17 Correct 36 ms 7732 KB Output is correct
18 Correct 80 ms 9476 KB Output is correct
19 Correct 92 ms 10088 KB Output is correct
20 Correct 60 ms 7484 KB Output is correct
21 Correct 60 ms 7576 KB Output is correct
22 Correct 48 ms 8852 KB Output is correct
23 Incorrect 0 ms 4428 KB Output isn't correct
24 Halted 0 ms 0 KB -