Submission #546184

# Submission time Handle Problem Language Result Execution time Memory
546184 2022-04-06T15:29:41 Z keta_tsimakuridze Parachute rings (IOI12_rings) C++14
100 / 100
1616 ms 111660 KB
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pii pair<int,int>
const int N = 1e6 + 5;
int n, sz = 0, h[N];
int cycle[6], tried[6] , rem[6], stop = 0, p[N][6], built[2], d[6][N];
pii deg;
vector<int> V[N];
void Init(int N_) {
  n = N_;
  for(int i = 0; i < n; i++) {
  	for(int t = 0; t < 6; t++) {
  		p[i][t] = i;
	}
  }
}
int find(int a, int t) {
	return (p[a][t] == a ? p[a][t] :  p[a][t] = find(p[a][t], t));	
}
void merge(int a,int b, int t) {
	a = find(a, t); b = find(b, t);
	if(a == b) return;
	p[a][t] = b;
	return;
}
void dfs(int a, int p) {
	if(p == -1) h[a] = 1;
	else
	h[a] = h[p] + 1;
	for(int i = 0; i < V[a].size(); i++) {
		if(V[a][i] == p) continue;
		if(sz) return;
		if(h[V[a][i]]) { 
			sz = h[a] - h[V[a][i]] + 1;
			return;
		} else dfs(V[a][i], a);
	}
}
void add(int a, int b, int t) {
	if(a == rem[t] || b == rem[t]) return;
	d[t][a]++; d[t][b]++;
	tried[t] = max(tried[t], max(d[t][a],d[t][b]));
	if(find(a, t) == find(b, t)) cycle[t] = 1;
	else merge(a, b, t);
	return;	
}
void Link(int a, int b) {
	if(stop) return;
	V[a].push_back(b); V[b].push_back(a);
	deg = max(deg, {(int)V[a].size(), a});
	deg = max(deg, {(int)V[b].size(), b});
	if(find(a, 5) != find(b, 5)) {
		merge(a, b, 5);
	}
	else {
		if(!cycle[5]) {
			merge(a, b, 5);
			dfs(a, -1);
			cycle[5] = a + 1;
		}
		else if(find(a, 5) != find(cycle[5] - 1, 5)) {
			stop = 1;
		}
	}
	if(built[0]) {
		add(a, b, 0);
	}
	if(built[1]) {
		for(int i = 1; i <= 4; i++) add(a, b, i);
	}
	
}
void build(int t) {
	int u = rem[t];
	for(int i = 0; i < n; i++) {
		if(u == i) continue;
		for(int j = 0; j < V[i].size(); j++) {
			int v = V[i][j];
			if(v == u || v < i) continue;
			if(find(v, t) == find(i, t)) cycle[t] = 1;
			merge(i, v, t);
			d[t][v]++; d[t][i]++;
		}
	}
	for(int i = 0; i < n; i++) tried[t] = max(tried[t], d[t][i]);	
}
int CountCritical() {
	if(stop) return 0; 
	if(!cycle[5] && deg.f <= 2) return n;
	if(deg.f <= 2) return sz;
	
	if(deg.f >= 4) {
		if(!built[0]) {
			built[0] = 1;
			rem[0] = deg.s;
			build(0);
		}
		if(tried[0] <= 2 && !cycle[0]) return 1;
		stop = 1;
		return 0;
	}
	if(!built[1]) {
		built[1] = 1;
		rem[1] = deg.s; 
		if(V[rem[1]].size() != 3) {
			return 342432;
		}
		for(int i = 0; i < V[rem[1]].size(); i++) {
			rem[i + 2] = V[rem[1]][i]; 
		}
		for(int i = 1; i <= 4; i++) {
			build(i);
		}
	}
	int cn = 0;
	for(int i = 1; i <= 4; i++) {
		if(tried[i] <= 2 && !cycle[i]) cn++;
	}
	if(!cn) stop = 1;
	return cn;
}

Compilation message

rings.cpp: In function 'void dfs(int, int)':
rings.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i = 0; i < V[a].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
rings.cpp: In function 'void build(int)':
rings.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for(int j = 0; j < V[i].size(); j++) {
      |                  ~~^~~~~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:110:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |   for(int i = 0; i < V[rem[1]].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 15 ms 24052 KB Output is correct
3 Correct 19 ms 24128 KB Output is correct
4 Correct 16 ms 23764 KB Output is correct
5 Correct 14 ms 24020 KB Output is correct
6 Correct 15 ms 24244 KB Output is correct
7 Correct 12 ms 24020 KB Output is correct
8 Correct 13 ms 24020 KB Output is correct
9 Correct 14 ms 24148 KB Output is correct
10 Correct 16 ms 24216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 52336 KB Output is correct
2 Correct 890 ms 70740 KB Output is correct
3 Correct 571 ms 66344 KB Output is correct
4 Correct 945 ms 80212 KB Output is correct
5 Correct 963 ms 83692 KB Output is correct
6 Correct 1100 ms 111660 KB Output is correct
7 Correct 1180 ms 81984 KB Output is correct
8 Correct 1514 ms 102168 KB Output is correct
9 Correct 1616 ms 107732 KB Output is correct
10 Correct 598 ms 91256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 15 ms 24052 KB Output is correct
3 Correct 19 ms 24128 KB Output is correct
4 Correct 16 ms 23764 KB Output is correct
5 Correct 14 ms 24020 KB Output is correct
6 Correct 15 ms 24244 KB Output is correct
7 Correct 12 ms 24020 KB Output is correct
8 Correct 13 ms 24020 KB Output is correct
9 Correct 14 ms 24148 KB Output is correct
10 Correct 16 ms 24216 KB Output is correct
11 Correct 18 ms 24148 KB Output is correct
12 Correct 21 ms 24532 KB Output is correct
13 Correct 22 ms 24644 KB Output is correct
14 Correct 16 ms 24276 KB Output is correct
15 Correct 16 ms 24612 KB Output is correct
16 Correct 15 ms 24404 KB Output is correct
17 Correct 15 ms 24148 KB Output is correct
18 Correct 17 ms 24716 KB Output is correct
19 Correct 18 ms 24404 KB Output is correct
20 Correct 19 ms 24604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 15 ms 24052 KB Output is correct
3 Correct 19 ms 24128 KB Output is correct
4 Correct 16 ms 23764 KB Output is correct
5 Correct 14 ms 24020 KB Output is correct
6 Correct 15 ms 24244 KB Output is correct
7 Correct 12 ms 24020 KB Output is correct
8 Correct 13 ms 24020 KB Output is correct
9 Correct 14 ms 24148 KB Output is correct
10 Correct 16 ms 24216 KB Output is correct
11 Correct 18 ms 24148 KB Output is correct
12 Correct 21 ms 24532 KB Output is correct
13 Correct 22 ms 24644 KB Output is correct
14 Correct 16 ms 24276 KB Output is correct
15 Correct 16 ms 24612 KB Output is correct
16 Correct 15 ms 24404 KB Output is correct
17 Correct 15 ms 24148 KB Output is correct
18 Correct 17 ms 24716 KB Output is correct
19 Correct 18 ms 24404 KB Output is correct
20 Correct 19 ms 24604 KB Output is correct
21 Correct 38 ms 26008 KB Output is correct
22 Correct 43 ms 27196 KB Output is correct
23 Correct 57 ms 28160 KB Output is correct
24 Correct 51 ms 28184 KB Output is correct
25 Correct 29 ms 28792 KB Output is correct
26 Correct 62 ms 30416 KB Output is correct
27 Correct 47 ms 28216 KB Output is correct
28 Correct 34 ms 27556 KB Output is correct
29 Correct 38 ms 28092 KB Output is correct
30 Correct 69 ms 30384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 15 ms 24052 KB Output is correct
3 Correct 19 ms 24128 KB Output is correct
4 Correct 16 ms 23764 KB Output is correct
5 Correct 14 ms 24020 KB Output is correct
6 Correct 15 ms 24244 KB Output is correct
7 Correct 12 ms 24020 KB Output is correct
8 Correct 13 ms 24020 KB Output is correct
9 Correct 14 ms 24148 KB Output is correct
10 Correct 16 ms 24216 KB Output is correct
11 Correct 393 ms 52336 KB Output is correct
12 Correct 890 ms 70740 KB Output is correct
13 Correct 571 ms 66344 KB Output is correct
14 Correct 945 ms 80212 KB Output is correct
15 Correct 963 ms 83692 KB Output is correct
16 Correct 1100 ms 111660 KB Output is correct
17 Correct 1180 ms 81984 KB Output is correct
18 Correct 1514 ms 102168 KB Output is correct
19 Correct 1616 ms 107732 KB Output is correct
20 Correct 598 ms 91256 KB Output is correct
21 Correct 18 ms 24148 KB Output is correct
22 Correct 21 ms 24532 KB Output is correct
23 Correct 22 ms 24644 KB Output is correct
24 Correct 16 ms 24276 KB Output is correct
25 Correct 16 ms 24612 KB Output is correct
26 Correct 15 ms 24404 KB Output is correct
27 Correct 15 ms 24148 KB Output is correct
28 Correct 17 ms 24716 KB Output is correct
29 Correct 18 ms 24404 KB Output is correct
30 Correct 19 ms 24604 KB Output is correct
31 Correct 38 ms 26008 KB Output is correct
32 Correct 43 ms 27196 KB Output is correct
33 Correct 57 ms 28160 KB Output is correct
34 Correct 51 ms 28184 KB Output is correct
35 Correct 29 ms 28792 KB Output is correct
36 Correct 62 ms 30416 KB Output is correct
37 Correct 47 ms 28216 KB Output is correct
38 Correct 34 ms 27556 KB Output is correct
39 Correct 38 ms 28092 KB Output is correct
40 Correct 69 ms 30384 KB Output is correct
41 Correct 200 ms 47608 KB Output is correct
42 Correct 667 ms 79488 KB Output is correct
43 Correct 293 ms 72524 KB Output is correct
44 Correct 222 ms 73876 KB Output is correct
45 Correct 391 ms 89072 KB Output is correct
46 Correct 587 ms 81008 KB Output is correct
47 Correct 892 ms 103408 KB Output is correct
48 Correct 277 ms 71516 KB Output is correct
49 Correct 555 ms 83268 KB Output is correct
50 Correct 649 ms 82572 KB Output is correct
51 Correct 336 ms 67000 KB Output is correct
52 Correct 220 ms 64396 KB Output is correct
53 Correct 217 ms 70560 KB Output is correct
54 Correct 1208 ms 92320 KB Output is correct
55 Correct 1255 ms 101648 KB Output is correct