Submission #350960

# Submission time Handle Problem Language Result Execution time Memory
350960 2021-01-19T10:29:46 Z tengiz05 Parachute rings (IOI12_rings) C++17
55 / 100
4000 ms 68832 KB
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int Ni = 1e6+5;
vector<int> edges[Ni];
int n, ans;


// start of DSU
vector<int> p, sz, cyclic;
int par(int u){
	if(p[u] == u)return u;
	return p[u] = par(p[u]);
}
bool IsSame(int u, int v){
	return par(u) == par(v);
}
void merge(int u,int v){
	u=par(u);v=par(v);
	if(u == v)return;
	p[v] = u;
	sz[u] += sz[v];
	cyclic[u] |= cyclic[v];
	return;
}
int size_of_node(int u){
	return sz[par(u)];
}// end of DSU


int have_this_number_of_edges[5];
void Init(int N_) {
	n = N_;
	ans = n;
	p.assign(n,0);
	sz.assign(n,1);
	cyclic.assign(n,0);
	for(int i=0;i<n;i++)p[i] = i;
	have_this_number_of_edges[0] = n;
}
int number_of_cycles;
void del(int u){
	have_this_number_of_edges[min(4,(int)edges[u].size())]--;
}void add(int u){
	have_this_number_of_edges[min(4,(int)edges[u].size())]++;	
}
void Link(int u, int v){
	del(u);del(v);
	edges[u].pb(v);
	edges[v].pb(u);
	add(u);add(v);
	if(IsSame(u, v)){
		number_of_cycles++;
		cyclic[par(u)] = 1;
	}else {
		merge(u,v);
	}return;
}

int please_dont_go_there;
bool is_it_normal;
bool used[Ni];

void dfs(int u, int p){
	used[u] = true;
	int cnt = 0;
	for(auto v : edges[u]){
		if(v != please_dont_go_there)cnt++;
		if(v == p || v == please_dont_go_there)continue;
		if(used[v])is_it_normal = false;
		else dfs(v,u);
	}if(cnt>2)is_it_normal = false;
}

bool CheckItPlease(int to_delete){
	please_dont_go_there = to_delete;
	for(int j=0;j<n;j++)used[j] = false;
	used[please_dont_go_there] = true;
	is_it_normal = true;
	for(int j=0;j<n;j++){
		if(!used[j])dfs(j,j);
	}return is_it_normal;
}

int CountCritical(){
	if(have_this_number_of_edges[4] > 1)return 0;
	if(!number_of_cycles && have_this_number_of_edges[3]+have_this_number_of_edges[4]==0)return n;
	ans = 0;
	if(have_this_number_of_edges[4] == 1){
		int we_need_it;
		for(int i=0;i<n;i++){
			if(edges[i].size() >= 4){
				we_need_it = i;break;
			}
		}
		ans += CheckItPlease(we_need_it);
	}else if(have_this_number_of_edges[3] > 0){
		int we_need_it=-1;
		for(int i=0;i<n;i++){
			if(edges[i].size() == 3){
				we_need_it = i;break;
			}
		}assert(~we_need_it);
		ans += CheckItPlease(we_need_it);
		for(auto v : edges[we_need_it])ans += CheckItPlease(v);	
	}else if(have_this_number_of_edges[2] > 0){
		if(number_of_cycles > 1)return 0;
		for(int i=0;i<n;i++){
			if(cyclic[par(i)])return size_of_node(i);
		}assert(false);
	}else assert(false);
	return ans;
}

Compilation message

rings.cpp: In function 'int CountCritical()':
rings.cpp:99:23: warning: 'we_need_it' may be used uninitialized in this function [-Wmaybe-uninitialized]
   99 |   ans += CheckItPlease(we_need_it);
      |          ~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 18 ms 24044 KB Output is correct
3 Correct 18 ms 24044 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 17 ms 24068 KB Output is correct
7 Correct 18 ms 23916 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 18 ms 24172 KB Output is correct
10 Correct 18 ms 24044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 494 ms 46188 KB Output is correct
2 Correct 1148 ms 59284 KB Output is correct
3 Correct 1220 ms 63000 KB Output is correct
4 Correct 1157 ms 67016 KB Output is correct
5 Correct 1207 ms 66860 KB Output is correct
6 Correct 1178 ms 66028 KB Output is correct
7 Correct 1147 ms 62524 KB Output is correct
8 Correct 2054 ms 65644 KB Output is correct
9 Correct 2213 ms 68832 KB Output is correct
10 Correct 878 ms 65772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 18 ms 24044 KB Output is correct
3 Correct 18 ms 24044 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 17 ms 24068 KB Output is correct
7 Correct 18 ms 23916 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 18 ms 24172 KB Output is correct
10 Correct 18 ms 24044 KB Output is correct
11 Correct 32 ms 24044 KB Output is correct
12 Correct 26 ms 24448 KB Output is correct
13 Correct 49 ms 24300 KB Output is correct
14 Correct 30 ms 24172 KB Output is correct
15 Correct 39 ms 24300 KB Output is correct
16 Correct 20 ms 24300 KB Output is correct
17 Correct 85 ms 24260 KB Output is correct
18 Correct 27 ms 24556 KB Output is correct
19 Correct 19 ms 24300 KB Output is correct
20 Correct 65 ms 24428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 18 ms 24044 KB Output is correct
3 Correct 18 ms 24044 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 17 ms 24068 KB Output is correct
7 Correct 18 ms 23916 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 18 ms 24172 KB Output is correct
10 Correct 18 ms 24044 KB Output is correct
11 Correct 32 ms 24044 KB Output is correct
12 Correct 26 ms 24448 KB Output is correct
13 Correct 49 ms 24300 KB Output is correct
14 Correct 30 ms 24172 KB Output is correct
15 Correct 39 ms 24300 KB Output is correct
16 Correct 20 ms 24300 KB Output is correct
17 Correct 85 ms 24260 KB Output is correct
18 Correct 27 ms 24556 KB Output is correct
19 Correct 19 ms 24300 KB Output is correct
20 Correct 65 ms 24428 KB Output is correct
21 Correct 35 ms 25452 KB Output is correct
22 Correct 48 ms 26348 KB Output is correct
23 Correct 62 ms 27116 KB Output is correct
24 Execution timed out 4056 ms 26016 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 18 ms 24044 KB Output is correct
3 Correct 18 ms 24044 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 16 ms 23916 KB Output is correct
6 Correct 17 ms 24068 KB Output is correct
7 Correct 18 ms 23916 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 18 ms 24172 KB Output is correct
10 Correct 18 ms 24044 KB Output is correct
11 Correct 494 ms 46188 KB Output is correct
12 Correct 1148 ms 59284 KB Output is correct
13 Correct 1220 ms 63000 KB Output is correct
14 Correct 1157 ms 67016 KB Output is correct
15 Correct 1207 ms 66860 KB Output is correct
16 Correct 1178 ms 66028 KB Output is correct
17 Correct 1147 ms 62524 KB Output is correct
18 Correct 2054 ms 65644 KB Output is correct
19 Correct 2213 ms 68832 KB Output is correct
20 Correct 878 ms 65772 KB Output is correct
21 Correct 32 ms 24044 KB Output is correct
22 Correct 26 ms 24448 KB Output is correct
23 Correct 49 ms 24300 KB Output is correct
24 Correct 30 ms 24172 KB Output is correct
25 Correct 39 ms 24300 KB Output is correct
26 Correct 20 ms 24300 KB Output is correct
27 Correct 85 ms 24260 KB Output is correct
28 Correct 27 ms 24556 KB Output is correct
29 Correct 19 ms 24300 KB Output is correct
30 Correct 65 ms 24428 KB Output is correct
31 Correct 35 ms 25452 KB Output is correct
32 Correct 48 ms 26348 KB Output is correct
33 Correct 62 ms 27116 KB Output is correct
34 Execution timed out 4056 ms 26016 KB Time limit exceeded
35 Halted 0 ms 0 KB -