Submission #446550

# Submission time Handle Problem Language Result Execution time Memory
446550 2021-07-22T12:00:46 Z ComPhyPark Parachute rings (IOI12_rings) C++14
100 / 100
3794 ms 123480 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], ln[SZ];
	bool is3E[SZ], isCX[SZ];
	int x;
	void init() {
		x = n;
		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;
			sz[i] = 1;
			ln[i] = 0;
			is3E[i] = isCX[i] = false;
		}
	}
	void init(int X) {
		if (ifDebug)printf("init(%d)\n", X);
		init();
		x = X;
		PR();
		for (int i = 0; i < n; i++) {
			for (int e : l[i]) {
				if (e < i)Link(e, i);
			}
		}
		st[0] = st[1] = st[2] = st[3] = ts[1] = ts[2] = 0;
		for (int i = 0; i < n; i++) {
			st[min(gC(i), 3)]++;
			is3E[i] = false;
		}
		for (int i = 0; i < n; i++) {
			if (gC(i) > 2)is3E[f(i)] = true;
		}
		for (int i = 0; i < n; i++) {
			if (i == p[i])ts[gT(i)]++;
		}
	}
	int f(int a) {
		return a == p[a] ? a : p[a] = f(p[a]);
	}
	int gC(int A) {
		if (A == x)return 0;
		return l[A].size() - (isCX[A] ? 1 : 0);
	}
	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)]--;
			ln[a] += ln[b];
			sz[a] += sz[b];
			is3E[a] |= is3E[b];
		}
		else {
			ts[gT(a)]--;
		}
	}
	void Con(int A, int B) {
		int a = f(A);
		if (x == n) {
			st[min(gC(A), 3)]--;
			l[A].push_back(B);
			st[min(gC(A), 3)]++;
		}
		else {
			st[min(gC(A) - 1, 3)]--;
			st[min(gC(A), 3)]++;
		}
		if (gC(A) >= 3)is3E[a] = true;
	}
	int gT(int a) {
		if (is3E[a]) {
			return 2;
		}
		else if (sz[a] == ln[a]) {
			return 1;
		}
		else {
			return 0;
		}
	}
	void Link(int A, int B) {
		if (A == x || B == x) {
			isCX[A + B - x] = true;
			return;
		}
		if (ifDebug)printf("%d:%d-%d\n", x, A, B);
		u(A, B);
		Con(A, B);
		Con(B, A);
		int a = f(A);
		ln[a]++;
		ts[gT(a)]++;
	}
	bool isChain() {
		return (ts[1] + ts[2] == 0);
	}
	void PR() {
		if (!ifDebug)return;
		printf("-------%d-------\n", x);
		printf("%d %d %d %d\n", st[0], st[1], st[2], st[3]);
		printf("%d %d %d\n", ts[0], ts[1], ts[2]);
		for (int a = 0; a < n; a++) {
			printf("(%d)", gC(a));
			if (a == p[a]) {
				printf("[%d(%d,%d,%d)]", a, sz[a], gT(a), ln[a]);
				printf("\n");
			}
			else {
				printf("%d->%d\n", a, f(a));
			}
		}
		printf("-----------------\n");
	}
}Graph;
Graph MG, GV[4];
int GS;
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("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
		int a = A;
		if (l[A].size() < 3)a = B;
		GS = l[a].size() + 1;
		GV[l[a].size()].init(a);
		for (int i = 0; i < l[a].size(); i++) {
			GV[i].init(l[a][i]);
		}
	}
}
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;
	}
}

Compilation message

rings.cpp: In function 'void Link(int, int)':
rings.cpp:147:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  147 |   for (int i = 0; i < l[a].size(); i++) {
      |                   ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 18 ms 24396 KB Output is correct
3 Correct 19 ms 24476 KB Output is correct
4 Correct 14 ms 23868 KB Output is correct
5 Correct 16 ms 23872 KB Output is correct
6 Correct 18 ms 24080 KB Output is correct
7 Correct 15 ms 24284 KB Output is correct
8 Correct 16 ms 23960 KB Output is correct
9 Correct 18 ms 24396 KB Output is correct
10 Correct 18 ms 24412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 530 ms 47200 KB Output is correct
2 Correct 2731 ms 103808 KB Output is correct
3 Correct 3794 ms 119416 KB Output is correct
4 Correct 1154 ms 68712 KB Output is correct
5 Correct 1177 ms 68848 KB Output is correct
6 Correct 1142 ms 67748 KB Output is correct
7 Correct 3706 ms 119060 KB Output is correct
8 Correct 2898 ms 117204 KB Output is correct
9 Correct 2967 ms 123480 KB Output is correct
10 Correct 848 ms 67624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 18 ms 24396 KB Output is correct
3 Correct 19 ms 24476 KB Output is correct
4 Correct 14 ms 23868 KB Output is correct
5 Correct 16 ms 23872 KB Output is correct
6 Correct 18 ms 24080 KB Output is correct
7 Correct 15 ms 24284 KB Output is correct
8 Correct 16 ms 23960 KB Output is correct
9 Correct 18 ms 24396 KB Output is correct
10 Correct 18 ms 24412 KB Output is correct
11 Correct 18 ms 24476 KB Output is correct
12 Correct 23 ms 25012 KB Output is correct
13 Correct 23 ms 24880 KB Output is correct
14 Correct 24 ms 24872 KB Output is correct
15 Correct 25 ms 25456 KB Output is correct
16 Correct 21 ms 24212 KB Output is correct
17 Correct 23 ms 24976 KB Output is correct
18 Correct 31 ms 25700 KB Output is correct
19 Correct 19 ms 24300 KB Output is correct
20 Correct 24 ms 24992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 18 ms 24396 KB Output is correct
3 Correct 19 ms 24476 KB Output is correct
4 Correct 14 ms 23868 KB Output is correct
5 Correct 16 ms 23872 KB Output is correct
6 Correct 18 ms 24080 KB Output is correct
7 Correct 15 ms 24284 KB Output is correct
8 Correct 16 ms 23960 KB Output is correct
9 Correct 18 ms 24396 KB Output is correct
10 Correct 18 ms 24412 KB Output is correct
11 Correct 18 ms 24476 KB Output is correct
12 Correct 23 ms 25012 KB Output is correct
13 Correct 23 ms 24880 KB Output is correct
14 Correct 24 ms 24872 KB Output is correct
15 Correct 25 ms 25456 KB Output is correct
16 Correct 21 ms 24212 KB Output is correct
17 Correct 23 ms 24976 KB Output is correct
18 Correct 31 ms 25700 KB Output is correct
19 Correct 19 ms 24300 KB Output is correct
20 Correct 24 ms 24992 KB Output is correct
21 Correct 33 ms 25480 KB Output is correct
22 Correct 46 ms 26564 KB Output is correct
23 Correct 53 ms 27164 KB Output is correct
24 Correct 124 ms 31780 KB Output is correct
25 Correct 45 ms 31044 KB Output is correct
26 Correct 134 ms 32660 KB Output is correct
27 Correct 69 ms 27696 KB Output is correct
28 Correct 148 ms 32752 KB Output is correct
29 Correct 105 ms 32432 KB Output is correct
30 Correct 77 ms 28212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 18 ms 24396 KB Output is correct
3 Correct 19 ms 24476 KB Output is correct
4 Correct 14 ms 23868 KB Output is correct
5 Correct 16 ms 23872 KB Output is correct
6 Correct 18 ms 24080 KB Output is correct
7 Correct 15 ms 24284 KB Output is correct
8 Correct 16 ms 23960 KB Output is correct
9 Correct 18 ms 24396 KB Output is correct
10 Correct 18 ms 24412 KB Output is correct
11 Correct 530 ms 47200 KB Output is correct
12 Correct 2731 ms 103808 KB Output is correct
13 Correct 3794 ms 119416 KB Output is correct
14 Correct 1154 ms 68712 KB Output is correct
15 Correct 1177 ms 68848 KB Output is correct
16 Correct 1142 ms 67748 KB Output is correct
17 Correct 3706 ms 119060 KB Output is correct
18 Correct 2898 ms 117204 KB Output is correct
19 Correct 2967 ms 123480 KB Output is correct
20 Correct 848 ms 67624 KB Output is correct
21 Correct 18 ms 24476 KB Output is correct
22 Correct 23 ms 25012 KB Output is correct
23 Correct 23 ms 24880 KB Output is correct
24 Correct 24 ms 24872 KB Output is correct
25 Correct 25 ms 25456 KB Output is correct
26 Correct 21 ms 24212 KB Output is correct
27 Correct 23 ms 24976 KB Output is correct
28 Correct 31 ms 25700 KB Output is correct
29 Correct 19 ms 24300 KB Output is correct
30 Correct 24 ms 24992 KB Output is correct
31 Correct 33 ms 25480 KB Output is correct
32 Correct 46 ms 26564 KB Output is correct
33 Correct 53 ms 27164 KB Output is correct
34 Correct 124 ms 31780 KB Output is correct
35 Correct 45 ms 31044 KB Output is correct
36 Correct 134 ms 32660 KB Output is correct
37 Correct 69 ms 27696 KB Output is correct
38 Correct 148 ms 32752 KB Output is correct
39 Correct 105 ms 32432 KB Output is correct
40 Correct 77 ms 28212 KB Output is correct
41 Correct 240 ms 39224 KB Output is correct
42 Correct 1335 ms 97152 KB Output is correct
43 Correct 495 ms 90872 KB Output is correct
44 Correct 2429 ms 115232 KB Output is correct
45 Correct 2469 ms 113144 KB Output is correct
46 Correct 805 ms 61688 KB Output is correct
47 Correct 991 ms 62508 KB Output is correct
48 Correct 1273 ms 108720 KB Output is correct
49 Correct 773 ms 63244 KB Output is correct
50 Correct 798 ms 62612 KB Output is correct
51 Correct 638 ms 83308 KB Output is correct
52 Correct 2069 ms 97116 KB Output is correct
53 Correct 1357 ms 109232 KB Output is correct
54 Correct 2711 ms 104556 KB Output is correct
55 Correct 3176 ms 111860 KB Output is correct