Submission #348411

# Submission time Handle Problem Language Result Execution time Memory
348411 2021-01-15T01:15:21 Z dennisstar Parachute rings (IOI12_rings) C++17
100 / 100
2230 ms 111620 KB
#include <bits/stdc++.h>
using namespace std;

const int MX = 1e6 + 5;

int N, deg[MX], cy, fl;
int dd[4][MX], p[4][MX], chk[4];
vector<int> adj[MX];

int pr[MX], sz[MX];
int gp(int a) { return pr[a]?(pr[a]=gp(pr[a])):a; }
bool un(int a, int b) {
	a=gp(a), b=gp(b);
	if (a!=b) {
		pr[b]=a;
		sz[a]+=sz[b];
	}
	return a!=b;
}

int gp(int a, int *p) { return p[a]?(p[a]=gp(p[a], p)):a; }
bool un(int a, int b, int *p) {
	a=gp(a, p), b=gp(b, p);
	if (a!=b) p[b]=a;
	return a!=b;
}

vector<int> al;
void add(int u, int v) {
	for (int t=0; t<al.size(); t++) {
		int i=al[t];
		if (i==u||i==v) continue;
		if (!un(u, v, p[t])) chk[t]=0;
		dd[t][u]++, dd[t][v]++;
		if (dd[t][u]>=3||dd[t][v]>=3) chk[t]=0;
	}
}
void init(int x) {
	al.emplace_back(x);
	for (auto &i:adj[x]) al.emplace_back(i);
	for (int i=0; i<al.size(); i++) chk[i]=1;
	for (int i=1; i<=N; i++) for (auto &j:adj[i]) if (i<j) add(i, j);
}

void Init(int N) {
	::N=N;
	fill(sz, sz+N+1, 1);
}

void Link(int a, int b) {
	a++; b++;
	deg[a]++; deg[b]++;
	adj[a].emplace_back(b);
	adj[b].emplace_back(a);
	if (!fl&&deg[a]==3) fl=1, init(a);
	else if (!fl&&deg[b]==3) fl=1, init(b);
	else if (!fl) {
		if (!un(a, b)) {
			if (cy) cy=-1;
			else cy=gp(a);
		}
	}
	else add(a, b);
}

int CountCritical() {
	if (cy==-1) return 0;
	else if (!fl) return cy?sz[cy]:N;
	else {
		int c=0;
		for (int i=0; i<al.size(); i++) c+=chk[i];
		return c;
	}
}

Compilation message

rings.cpp: In function 'void add(int, int)':
rings.cpp:30:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for (int t=0; t<al.size(); t++) {
      |                ~^~~~~~~~~~
rings.cpp: In function 'void init(int)':
rings.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i=0; i<al.size(); i++) chk[i]=1;
      |                ~^~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:71:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for (int i=0; i<al.size(); i++) c+=chk[i];
      |                 ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 17 ms 24300 KB Output is correct
3 Correct 20 ms 24300 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23936 KB Output is correct
6 Correct 18 ms 24192 KB Output is correct
7 Correct 18 ms 24172 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 18 ms 24300 KB Output is correct
10 Correct 17 ms 24300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 476 ms 53408 KB Output is correct
2 Correct 1263 ms 94236 KB Output is correct
3 Correct 2230 ms 106976 KB Output is correct
4 Correct 1151 ms 80492 KB Output is correct
5 Correct 1184 ms 80524 KB Output is correct
6 Correct 1128 ms 79044 KB Output is correct
7 Correct 2106 ms 105860 KB Output is correct
8 Correct 1537 ms 106348 KB Output is correct
9 Correct 1655 ms 111620 KB Output is correct
10 Correct 799 ms 79236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 17 ms 24300 KB Output is correct
3 Correct 20 ms 24300 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23936 KB Output is correct
6 Correct 18 ms 24192 KB Output is correct
7 Correct 18 ms 24172 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 18 ms 24300 KB Output is correct
10 Correct 17 ms 24300 KB Output is correct
11 Correct 18 ms 24300 KB Output is correct
12 Correct 20 ms 24812 KB Output is correct
13 Correct 21 ms 24812 KB Output is correct
14 Correct 19 ms 24556 KB Output is correct
15 Correct 20 ms 24940 KB Output is correct
16 Correct 21 ms 24448 KB Output is correct
17 Correct 20 ms 24812 KB Output is correct
18 Correct 21 ms 25324 KB Output is correct
19 Correct 20 ms 24428 KB Output is correct
20 Correct 20 ms 24812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 17 ms 24300 KB Output is correct
3 Correct 20 ms 24300 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23936 KB Output is correct
6 Correct 18 ms 24192 KB Output is correct
7 Correct 18 ms 24172 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 18 ms 24300 KB Output is correct
10 Correct 17 ms 24300 KB Output is correct
11 Correct 18 ms 24300 KB Output is correct
12 Correct 20 ms 24812 KB Output is correct
13 Correct 21 ms 24812 KB Output is correct
14 Correct 19 ms 24556 KB Output is correct
15 Correct 20 ms 24940 KB Output is correct
16 Correct 21 ms 24448 KB Output is correct
17 Correct 20 ms 24812 KB Output is correct
18 Correct 21 ms 25324 KB Output is correct
19 Correct 20 ms 24428 KB Output is correct
20 Correct 20 ms 24812 KB Output is correct
21 Correct 33 ms 25836 KB Output is correct
22 Correct 46 ms 26988 KB Output is correct
23 Correct 58 ms 28012 KB Output is correct
24 Correct 82 ms 29932 KB Output is correct
25 Correct 34 ms 28396 KB Output is correct
26 Correct 70 ms 31084 KB Output is correct
27 Correct 64 ms 28780 KB Output is correct
28 Correct 78 ms 31596 KB Output is correct
29 Correct 60 ms 30444 KB Output is correct
30 Correct 83 ms 29548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 17 ms 24300 KB Output is correct
3 Correct 20 ms 24300 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23936 KB Output is correct
6 Correct 18 ms 24192 KB Output is correct
7 Correct 18 ms 24172 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 18 ms 24300 KB Output is correct
10 Correct 17 ms 24300 KB Output is correct
11 Correct 476 ms 53408 KB Output is correct
12 Correct 1263 ms 94236 KB Output is correct
13 Correct 2230 ms 106976 KB Output is correct
14 Correct 1151 ms 80492 KB Output is correct
15 Correct 1184 ms 80524 KB Output is correct
16 Correct 1128 ms 79044 KB Output is correct
17 Correct 2106 ms 105860 KB Output is correct
18 Correct 1537 ms 106348 KB Output is correct
19 Correct 1655 ms 111620 KB Output is correct
20 Correct 799 ms 79236 KB Output is correct
21 Correct 18 ms 24300 KB Output is correct
22 Correct 20 ms 24812 KB Output is correct
23 Correct 21 ms 24812 KB Output is correct
24 Correct 19 ms 24556 KB Output is correct
25 Correct 20 ms 24940 KB Output is correct
26 Correct 21 ms 24448 KB Output is correct
27 Correct 20 ms 24812 KB Output is correct
28 Correct 21 ms 25324 KB Output is correct
29 Correct 20 ms 24428 KB Output is correct
30 Correct 20 ms 24812 KB Output is correct
31 Correct 33 ms 25836 KB Output is correct
32 Correct 46 ms 26988 KB Output is correct
33 Correct 58 ms 28012 KB Output is correct
34 Correct 82 ms 29932 KB Output is correct
35 Correct 34 ms 28396 KB Output is correct
36 Correct 70 ms 31084 KB Output is correct
37 Correct 64 ms 28780 KB Output is correct
38 Correct 78 ms 31596 KB Output is correct
39 Correct 60 ms 30444 KB Output is correct
40 Correct 83 ms 29548 KB Output is correct
41 Correct 241 ms 41900 KB Output is correct
42 Correct 738 ms 82976 KB Output is correct
43 Correct 324 ms 67564 KB Output is correct
44 Correct 1034 ms 103756 KB Output is correct
45 Correct 1394 ms 96944 KB Output is correct
46 Correct 745 ms 71660 KB Output is correct
47 Correct 980 ms 72672 KB Output is correct
48 Correct 648 ms 89868 KB Output is correct
49 Correct 726 ms 71788 KB Output is correct
50 Correct 772 ms 71276 KB Output is correct
51 Correct 367 ms 65644 KB Output is correct
52 Correct 939 ms 88812 KB Output is correct
53 Correct 661 ms 89940 KB Output is correct
54 Correct 1313 ms 95724 KB Output is correct
55 Correct 1373 ms 101612 KB Output is correct