Submission #443946

# Submission time Handle Problem Language Result Execution time Memory
443946 2021-07-12T14:25:07 Z ComPhyPark Parachute rings (IOI12_rings) C++14
100 / 100
3458 ms 192240 KB
#include<cstdio>
#include<vector>
using namespace std;
const int SZ = 1000010;
int min(int a, int b) { return a < b ? a : b; }
int n;
const bool ifDebug = false;
int cycleNum;
vector<int>l[SZ];
typedef struct Graph {
	int st[4], ts[3];
	int p[SZ], sz[SZ], cs[SZ][4], c[SZ];
	int x;
	bool isMain;
	void init() {
		x = n;
		isMain = true;
		st[0] = ts[0] = n;
		st[1] = st[2] = st[3] = ts[1] = ts[2] = 0;
		for (int i = 0; i < n; i++) {
			p[i] = i;
			cs[i][0] = sz[i] = 1;
			cs[i][1] = cs[i][2] = cs[i][3] = c[i] = 0;
		}
	}
	void init(int X) {
		if(ifDebug)printf("init(%d)\n", X);
		init();
		isMain = false;
		x = X;
		PR();
		for (int i = 0; i < n; i++) {
			for (int e : l[i]) {
				if (e < i)Link(e, i);
			}
		}
	}
	int f(int a) {
		return a == p[a] ? a : p[a] = f(p[a]);
	}
	void u(int A, int B) {
		int a = f(A), b = f(B);
		if (a != b) {
			p[b] = a;
			ts[gT(a)]--;
			ts[gT(b)]--;
			for (int i = 0; i < 4; i++) {
				cs[a][i] += cs[b][i];
			}
			sz[a] += sz[b];
		}
		else {
			ts[gT(a)]--;
		}
	}
	void Con(int A, int B) {
		int a = f(A);
		cs[a][min(c[A], 3)]--;
		st[min(c[A], 3)]--;
		if(isMain)l[A].push_back(B);
		c[A]++;
		cs[a][min(c[A], 3)]++;
		st[min(c[A], 3)]++;
	}
	int gT(int a) {
		if (cs[a][3]) {
			return 2;
		}
		else if (cs[a][2] && (cs[a][1] + cs[a][0] == 0)) {
			return 1;
		}
		else {
			return 0;
		}
	}
	void Link(int A, int B) {
		if (A == x || B == x)return;
		if (ifDebug)printf("%d:%d-%d\n", x, A, B);
		u(A, B);
		Con(A, B);
		Con(B, A);
		int a = f(A);
		ts[gT(a)]++;
	}
	bool isChain() {
		return (ts[1] + ts[2] == 0);
	}
	void PR() {
		if (!ifDebug)return;
		printf("-------%d-------\n", x);
		for (int a = 0; a < n; a++) {
			printf("(%d)", c[a]);
			if (a == p[a]) {
				printf("[%d(%d,%d)]", a, sz[a], gT(a));
				for (int b = 0; b < 4; b++)printf(" %d", cs[a][b]);
				printf("\n");
			}
			else {
				printf("%d->%d\n", a, f(a));
			}
		}
		printf("-----------------\n");
	}
}Graph;
Graph MG, GV[4];
int GS;
//type: 0-chain/1-cycle/2-3 exists/3-4 exists
void Init(int N) {
	cycleNum = n = N;
	MG.init();
}
void Link(int A, int B) {
	bool p = (MG.st[3] == 0);
	MG.Link(A, B);
	for (int i = 0; i < GS; i++) {
		GV[i].Link(A, B);
	}
	if (MG.gT(MG.f(A)) == 1)cycleNum = MG.f(A);
	if (MG.gT(MG.f(B)) == 1)cycleNum = MG.f(B);
	if (p && MG.st[3]) {
		if (ifDebug)printf("걸렸구나!!!!!!!!!\n");
		int a = A;
		if (l[A].size() < 3)a = B;
		GV[GS++].init(a);
		//return;
		for (int e : l[a]) {
			GV[GS++].init(e);
		}
	}
}
int CountCritical() {
	if (MG.ts[2]) {
		if (ifDebug)printf(">=3 Exists");
		int r = 0;
		for (int i = 0; i < GS; i++) {
			if (GV[i].isChain())r++;
		}
		return r;
	}
	else if (MG.ts[1]) {
		if (ifDebug)printf("cycle Exists");
		if (MG.ts[1] > 1)return 0;
		return MG.sz[cycleNum];
	}
	else {
		if (ifDebug)printf("Already Chain");
		return n;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 16 ms 24576 KB Output is correct
3 Correct 17 ms 24780 KB Output is correct
4 Correct 13 ms 23772 KB Output is correct
5 Correct 14 ms 24028 KB Output is correct
6 Correct 15 ms 24080 KB Output is correct
7 Correct 15 ms 24644 KB Output is correct
8 Correct 15 ms 24012 KB Output is correct
9 Correct 17 ms 24780 KB Output is correct
10 Correct 18 ms 24852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 504 ms 55228 KB Output is correct
2 Correct 2337 ms 159068 KB Output is correct
3 Correct 3458 ms 188780 KB Output is correct
4 Correct 1168 ms 82732 KB Output is correct
5 Correct 1190 ms 82764 KB Output is correct
6 Correct 1148 ms 81844 KB Output is correct
7 Correct 3297 ms 187732 KB Output is correct
8 Correct 2598 ms 181568 KB Output is correct
9 Correct 2697 ms 192240 KB Output is correct
10 Correct 861 ms 81604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 16 ms 24576 KB Output is correct
3 Correct 17 ms 24780 KB Output is correct
4 Correct 13 ms 23772 KB Output is correct
5 Correct 14 ms 24028 KB Output is correct
6 Correct 15 ms 24080 KB Output is correct
7 Correct 15 ms 24644 KB Output is correct
8 Correct 15 ms 24012 KB Output is correct
9 Correct 17 ms 24780 KB Output is correct
10 Correct 18 ms 24852 KB Output is correct
11 Correct 19 ms 24828 KB Output is correct
12 Correct 21 ms 25664 KB Output is correct
13 Correct 21 ms 25688 KB Output is correct
14 Correct 19 ms 25504 KB Output is correct
15 Correct 20 ms 26828 KB Output is correct
16 Correct 18 ms 24420 KB Output is correct
17 Correct 22 ms 25760 KB Output is correct
18 Correct 24 ms 27256 KB Output is correct
19 Correct 18 ms 24436 KB Output is correct
20 Correct 22 ms 25732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 16 ms 24576 KB Output is correct
3 Correct 17 ms 24780 KB Output is correct
4 Correct 13 ms 23772 KB Output is correct
5 Correct 14 ms 24028 KB Output is correct
6 Correct 15 ms 24080 KB Output is correct
7 Correct 15 ms 24644 KB Output is correct
8 Correct 15 ms 24012 KB Output is correct
9 Correct 17 ms 24780 KB Output is correct
10 Correct 18 ms 24852 KB Output is correct
11 Correct 19 ms 24828 KB Output is correct
12 Correct 21 ms 25664 KB Output is correct
13 Correct 21 ms 25688 KB Output is correct
14 Correct 19 ms 25504 KB Output is correct
15 Correct 20 ms 26828 KB Output is correct
16 Correct 18 ms 24420 KB Output is correct
17 Correct 22 ms 25760 KB Output is correct
18 Correct 24 ms 27256 KB Output is correct
19 Correct 18 ms 24436 KB Output is correct
20 Correct 22 ms 25732 KB Output is correct
21 Correct 33 ms 26316 KB Output is correct
22 Correct 49 ms 27700 KB Output is correct
23 Correct 57 ms 28744 KB Output is correct
24 Correct 134 ms 38320 KB Output is correct
25 Correct 40 ms 37976 KB Output is correct
26 Correct 123 ms 39208 KB Output is correct
27 Correct 63 ms 28996 KB Output is correct
28 Correct 161 ms 38880 KB Output is correct
29 Correct 97 ms 39392 KB Output is correct
30 Correct 89 ms 29716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 16 ms 24576 KB Output is correct
3 Correct 17 ms 24780 KB Output is correct
4 Correct 13 ms 23772 KB Output is correct
5 Correct 14 ms 24028 KB Output is correct
6 Correct 15 ms 24080 KB Output is correct
7 Correct 15 ms 24644 KB Output is correct
8 Correct 15 ms 24012 KB Output is correct
9 Correct 17 ms 24780 KB Output is correct
10 Correct 18 ms 24852 KB Output is correct
11 Correct 504 ms 55228 KB Output is correct
12 Correct 2337 ms 159068 KB Output is correct
13 Correct 3458 ms 188780 KB Output is correct
14 Correct 1168 ms 82732 KB Output is correct
15 Correct 1190 ms 82764 KB Output is correct
16 Correct 1148 ms 81844 KB Output is correct
17 Correct 3297 ms 187732 KB Output is correct
18 Correct 2598 ms 181568 KB Output is correct
19 Correct 2697 ms 192240 KB Output is correct
20 Correct 861 ms 81604 KB Output is correct
21 Correct 19 ms 24828 KB Output is correct
22 Correct 21 ms 25664 KB Output is correct
23 Correct 21 ms 25688 KB Output is correct
24 Correct 19 ms 25504 KB Output is correct
25 Correct 20 ms 26828 KB Output is correct
26 Correct 18 ms 24420 KB Output is correct
27 Correct 22 ms 25760 KB Output is correct
28 Correct 24 ms 27256 KB Output is correct
29 Correct 18 ms 24436 KB Output is correct
30 Correct 22 ms 25732 KB Output is correct
31 Correct 33 ms 26316 KB Output is correct
32 Correct 49 ms 27700 KB Output is correct
33 Correct 57 ms 28744 KB Output is correct
34 Correct 134 ms 38320 KB Output is correct
35 Correct 40 ms 37976 KB Output is correct
36 Correct 123 ms 39208 KB Output is correct
37 Correct 63 ms 28996 KB Output is correct
38 Correct 161 ms 38880 KB Output is correct
39 Correct 97 ms 39392 KB Output is correct
40 Correct 89 ms 29716 KB Output is correct
41 Correct 253 ms 46280 KB Output is correct
42 Correct 1184 ms 154800 KB Output is correct
43 Correct 458 ms 154308 KB Output is correct
44 Correct 2074 ms 178820 KB Output is correct
45 Correct 2252 ms 180940 KB Output is correct
46 Correct 800 ms 73132 KB Output is correct
47 Correct 1025 ms 74128 KB Output is correct
48 Correct 1147 ms 177504 KB Output is correct
49 Correct 767 ms 77016 KB Output is correct
50 Correct 801 ms 76232 KB Output is correct
51 Correct 579 ms 137436 KB Output is correct
52 Correct 1743 ms 147552 KB Output is correct
53 Correct 1182 ms 177716 KB Output is correct
54 Correct 2299 ms 159616 KB Output is correct
55 Correct 2734 ms 172216 KB Output is correct