Submission #3819

# Submission time Handle Problem Language Result Execution time Memory
3819 2013-08-31T08:33:57 Z imsifile Cactus? Not cactus? (kriii1_C) C++
0 / 1
40 ms 6296 KB
#include<stdio.h>
#include<stdlib.h>

int n, m, par[111111], lv[111111], go[111111];
int ecn, enp[222222], prv[222222], top[111111];
int scn, ix[111111], stk[111111], chk[111111];
int lst, dd[111111];

void edg(int s, int e){
	enp[ecn]=e, prv[ecn]=top[s], top[s]=ecn++;
}

void dfs(int k){
	int s, e;
	stk[scn++]=k, par[k]=-1, chk[k]=lv[k]=1, go[k]=k;
	dd[0]=k, lst++;
	while(scn){
		s=stk[scn-1];
		if(ix[s]==-1){
			scn--;
			if(par[s]!=-1){
				if(lv[go[par[s]]]>lv[go[s]])go[par[s]]=go[s];
			}
			if(s==4){
				e=3;
			}
			continue;
		}
		e=enp[ix[s]], ix[s]=prv[ix[s]];
		if(e==par[s] || lv[e]-lv[s]>1)continue;
		if(chk[e]){
			if(lv[s]>lv[go[s]]){
				puts("Not cactus");
				exit(0);
			}
			go[s]=e;
			continue;
		}
		lv[e]=lv[s]+1, go[e]=e, par[e]=s;
		stk[scn++]=e, chk[e]=1, dd[lst++]=e;
	}
	int i;
	for(i=0; i<lst; i++){
		s=dd[i];
		if(lv[go[go[s]]] != lv[go[s]]){
			puts("Not cactus");
			exit(0);
		}
	}
}

int main(){
	int i, a, b;
	scanf("%d%d", &n, &m);
	for(i=0; i<n; i++)top[i]=-1;
	for(i=0; i<m; i++){
		scanf("%d%d", &a, &b), a--, b--;
		edg(a,b), edg(b,a);
	}
	for(i=0; i<n; i++)ix[i]=top[i];
	for(i=0; i<n; i++){
		if(chk[i])continue;
		dfs(i);
	}
	puts("Cactus");
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6296 KB Output is correct
2 Correct 0 ms 6296 KB Output is correct
3 Correct 0 ms 6296 KB Output is correct
4 Correct 0 ms 6296 KB Output is correct
5 Correct 0 ms 6296 KB Output is correct
6 Correct 0 ms 6296 KB Output is correct
7 Correct 0 ms 6296 KB Output is correct
8 Correct 0 ms 6296 KB Output is correct
9 Correct 0 ms 6296 KB Output is correct
10 Correct 28 ms 6296 KB Output is correct
11 Correct 20 ms 6296 KB Output is correct
12 Correct 20 ms 6296 KB Output is correct
13 Correct 28 ms 6296 KB Output is correct
14 Correct 28 ms 6296 KB Output is correct
15 Correct 28 ms 6296 KB Output is correct
16 Correct 16 ms 6296 KB Output is correct
17 Correct 24 ms 6296 KB Output is correct
18 Correct 28 ms 6296 KB Output is correct
19 Correct 32 ms 6296 KB Output is correct
20 Correct 24 ms 6296 KB Output is correct
21 Correct 40 ms 6296 KB Output is correct
22 Correct 36 ms 6296 KB Output is correct
23 Incorrect 0 ms 6296 KB Output isn't correct
24 Halted 0 ms 0 KB -