Submission #3598

# Submission time Handle Problem Language Result Execution time Memory
3598 2013-08-31T06:48:46 Z movie_jo Cactus? Not cactus? (kriii1_C) C
0 / 1
28 ms 2260 KB
#include <stdio.h>

int x[100001];
int group[100001], gl = 1;
int cycle[100001];
int main(void)
{
	int N, M, i, a, b, y, z, chk = 0;

	scanf("%d %d", &N, &M);

	for(i = 0; i < M; i++)
	{
		scanf("%d %d", &a, &b);

		if(chk)
			continue;

		if(x[a])
		{
			if(x[b])
			{
				y = x[a];
				z = x[b];

				while(group[y] != y)
					y = group[y];

				while(group[z] != z)
					z = group[z];

				if(y == z)
				{
					cycle[y]++;

					if(cycle[y] > 1)
						chk = 1;
				}
				else
				{
					if(y > z)
					{
						group[y] = z;
						group[x[a]] = z;
					}
					else
					{
						group[z] = y;
						group[x[b]] = y;
					}
				}

			}
			else
			{
				x[b] = x[a];
			}
		}
		else if(x[b])
		{
			x[a] = x[b];
		}
		else
		{
			x[a] = gl;
			x[b] = gl;
			group[gl] = gl;
			gl++;
		}
	}

	printf("%sactus\n", chk?"Not c":"C");

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
3 Correct 0 ms 2260 KB Output is correct
4 Correct 0 ms 2260 KB Output is correct
5 Correct 0 ms 2260 KB Output is correct
6 Correct 0 ms 2260 KB Output is correct
7 Correct 0 ms 2260 KB Output is correct
8 Correct 0 ms 2260 KB Output is correct
9 Correct 0 ms 2260 KB Output is correct
10 Correct 12 ms 2260 KB Output is correct
11 Correct 20 ms 2260 KB Output is correct
12 Correct 16 ms 2260 KB Output is correct
13 Correct 16 ms 2260 KB Output is correct
14 Correct 20 ms 2260 KB Output is correct
15 Correct 20 ms 2260 KB Output is correct
16 Correct 12 ms 2260 KB Output is correct
17 Correct 16 ms 2260 KB Output is correct
18 Correct 20 ms 2260 KB Output is correct
19 Correct 28 ms 2260 KB Output is correct
20 Correct 16 ms 2260 KB Output is correct
21 Correct 20 ms 2260 KB Output is correct
22 Correct 20 ms 2260 KB Output is correct
23 Correct 0 ms 2260 KB Output is correct
24 Correct 0 ms 2260 KB Output is correct
25 Correct 0 ms 2260 KB Output is correct
26 Correct 16 ms 2260 KB Output is correct
27 Correct 12 ms 2260 KB Output is correct
28 Correct 20 ms 2260 KB Output is correct
29 Correct 20 ms 2260 KB Output is correct
30 Correct 20 ms 2260 KB Output is correct
31 Correct 16 ms 2260 KB Output is correct
32 Correct 20 ms 2260 KB Output is correct
33 Correct 24 ms 2260 KB Output is correct
34 Correct 24 ms 2260 KB Output is correct