Submission #62499

# Submission time Handle Problem Language Result Execution time Memory
62499 2018-07-28T19:34:23 Z zetapi Parachute rings (IOI12_rings) C++14
100 / 100
1040 ms 57172 KB
int n, cyc, Res;
int E[1010000][3], deg[5][1010000], chk[5], Num[5];
int par[5][1010000], SZ[1010000];
void Init(int N_) {
	n = N_;
	Res = n;
	int i;
	for (i = 1; i <= n; i++)SZ[i] = 1, par[0][i] = i;
}
 
int Find(int ck, int a){
	if (par[ck][a] == a)return a;
	return par[ck][a] = Find(ck, par[ck][a]);
}
 
void Add(int ck, int a, int b){
	if (chk[ck])return;
	if (ck && (Num[ck] == a || Num[ck] == b))return;
	if (!ck){
		E[a][deg[0][a]] = b, E[b][deg[0][b]] = a;
	}
	deg[ck][a]++, deg[ck][b]++;
	if (ck && (deg[ck][a] >= 3 || deg[ck][b] >= 3)){
		chk[ck] = 1;
		return;
	}
	a = Find(ck, a), b = Find(ck, b);
	if (a == b){
		if (!ck){
			cyc++;
			if (cyc == 1)Res = SZ[a];
		}
		else chk[ck] = 1;
	}
	else{
		par[ck][a] = b;
		if (!ck){
			SZ[b] += SZ[a];
			SZ[a] = 0;
		}
	}
}
 
void Make(int a){
	int i, j, k, x;
	Num[1] = a;
	for (i = 0; i < 3; i++){
		Num[2 + i] = E[a][i];
	}
	chk[0] = 1;
	for (k = 1; k <= 4; k++){
		for (i = 1; i <= n; i++)par[k][i] = i;
		for (i = 1; i <= n; i++){
			for (j = 0; j < deg[0][i]; j++){
				x = E[i][j];
				if (i == Num[k] || x == Num[k] || x > i)continue;
				Add(k, i, x);
			}
		}
	}
}
 
void Link(int A, int B) {
	if (!Res)return;
	A++, B++;
	if (!chk[0]){
		if (cyc == 2)Res = 0;
		Add(0, A, B);
		if (deg[0][A] == 3){
			Make(A);
		}
		else if (deg[0][B] == 3){
			Make(B);
		}
	}
	else{
		int i;
		for (i = 1; i <= 4; i++)Add(i, A, B);
	}
}
 
int CountCritical() {
	if (!chk[0]){
		if (cyc == 2)Res = 0;
		return Res;
	}
	int i, r = 0;
	for (i = 1; i <= 4; i++)if (!chk[i])r++;
	return r;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 628 KB Output is correct
3 Correct 3 ms 664 KB Output is correct
4 Correct 2 ms 664 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 3 ms 664 KB Output is correct
7 Correct 2 ms 848 KB Output is correct
8 Correct 3 ms 848 KB Output is correct
9 Correct 4 ms 924 KB Output is correct
10 Correct 4 ms 924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 312 ms 12828 KB Output is correct
2 Correct 534 ms 44464 KB Output is correct
3 Correct 385 ms 55260 KB Output is correct
4 Correct 823 ms 55260 KB Output is correct
5 Correct 838 ms 55260 KB Output is correct
6 Correct 828 ms 55260 KB Output is correct
7 Correct 351 ms 55392 KB Output is correct
8 Correct 904 ms 55392 KB Output is correct
9 Correct 1040 ms 55508 KB Output is correct
10 Correct 645 ms 55508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 628 KB Output is correct
3 Correct 3 ms 664 KB Output is correct
4 Correct 2 ms 664 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 3 ms 664 KB Output is correct
7 Correct 2 ms 848 KB Output is correct
8 Correct 3 ms 848 KB Output is correct
9 Correct 4 ms 924 KB Output is correct
10 Correct 4 ms 924 KB Output is correct
11 Correct 4 ms 55508 KB Output is correct
12 Correct 6 ms 55508 KB Output is correct
13 Correct 6 ms 55508 KB Output is correct
14 Correct 6 ms 55508 KB Output is correct
15 Correct 4 ms 55508 KB Output is correct
16 Correct 5 ms 55508 KB Output is correct
17 Correct 5 ms 55508 KB Output is correct
18 Correct 5 ms 55508 KB Output is correct
19 Correct 5 ms 55508 KB Output is correct
20 Correct 6 ms 55508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 628 KB Output is correct
3 Correct 3 ms 664 KB Output is correct
4 Correct 2 ms 664 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 3 ms 664 KB Output is correct
7 Correct 2 ms 848 KB Output is correct
8 Correct 3 ms 848 KB Output is correct
9 Correct 4 ms 924 KB Output is correct
10 Correct 4 ms 924 KB Output is correct
11 Correct 4 ms 55508 KB Output is correct
12 Correct 6 ms 55508 KB Output is correct
13 Correct 6 ms 55508 KB Output is correct
14 Correct 6 ms 55508 KB Output is correct
15 Correct 4 ms 55508 KB Output is correct
16 Correct 5 ms 55508 KB Output is correct
17 Correct 5 ms 55508 KB Output is correct
18 Correct 5 ms 55508 KB Output is correct
19 Correct 5 ms 55508 KB Output is correct
20 Correct 6 ms 55508 KB Output is correct
21 Correct 16 ms 55508 KB Output is correct
22 Correct 29 ms 55508 KB Output is correct
23 Correct 32 ms 55508 KB Output is correct
24 Correct 32 ms 55508 KB Output is correct
25 Correct 16 ms 55508 KB Output is correct
26 Correct 49 ms 55508 KB Output is correct
27 Correct 33 ms 55508 KB Output is correct
28 Correct 33 ms 55508 KB Output is correct
29 Correct 32 ms 55508 KB Output is correct
30 Correct 38 ms 55508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 628 KB Output is correct
3 Correct 3 ms 664 KB Output is correct
4 Correct 2 ms 664 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 3 ms 664 KB Output is correct
7 Correct 2 ms 848 KB Output is correct
8 Correct 3 ms 848 KB Output is correct
9 Correct 4 ms 924 KB Output is correct
10 Correct 4 ms 924 KB Output is correct
11 Correct 312 ms 12828 KB Output is correct
12 Correct 534 ms 44464 KB Output is correct
13 Correct 385 ms 55260 KB Output is correct
14 Correct 823 ms 55260 KB Output is correct
15 Correct 838 ms 55260 KB Output is correct
16 Correct 828 ms 55260 KB Output is correct
17 Correct 351 ms 55392 KB Output is correct
18 Correct 904 ms 55392 KB Output is correct
19 Correct 1040 ms 55508 KB Output is correct
20 Correct 645 ms 55508 KB Output is correct
21 Correct 4 ms 55508 KB Output is correct
22 Correct 6 ms 55508 KB Output is correct
23 Correct 6 ms 55508 KB Output is correct
24 Correct 6 ms 55508 KB Output is correct
25 Correct 4 ms 55508 KB Output is correct
26 Correct 5 ms 55508 KB Output is correct
27 Correct 5 ms 55508 KB Output is correct
28 Correct 5 ms 55508 KB Output is correct
29 Correct 5 ms 55508 KB Output is correct
30 Correct 6 ms 55508 KB Output is correct
31 Correct 16 ms 55508 KB Output is correct
32 Correct 29 ms 55508 KB Output is correct
33 Correct 32 ms 55508 KB Output is correct
34 Correct 32 ms 55508 KB Output is correct
35 Correct 16 ms 55508 KB Output is correct
36 Correct 49 ms 55508 KB Output is correct
37 Correct 33 ms 55508 KB Output is correct
38 Correct 33 ms 55508 KB Output is correct
39 Correct 32 ms 55508 KB Output is correct
40 Correct 38 ms 55508 KB Output is correct
41 Correct 186 ms 55508 KB Output is correct
42 Correct 539 ms 55508 KB Output is correct
43 Correct 293 ms 55508 KB Output is correct
44 Correct 345 ms 55508 KB Output is correct
45 Correct 499 ms 55776 KB Output is correct
46 Correct 562 ms 55776 KB Output is correct
47 Correct 685 ms 55776 KB Output is correct
48 Correct 322 ms 57172 KB Output is correct
49 Correct 572 ms 57172 KB Output is correct
50 Correct 605 ms 57172 KB Output is correct
51 Correct 244 ms 57172 KB Output is correct
52 Correct 325 ms 57172 KB Output is correct
53 Correct 293 ms 57172 KB Output is correct
54 Correct 759 ms 57172 KB Output is correct
55 Correct 492 ms 57172 KB Output is correct