Submission #350957

# Submission time Handle Problem Language Result Execution time Memory
350957 2021-01-19T10:23:29 Z tengiz05 Parachute rings (IOI12_rings) C++17
55 / 100
4000 ms 69772 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;
}

bool is_it_in_cycle[Ni];
int parent[Ni];
void PleaseFindCycles(int u, int p){
	parent[u] = p;
	used[u] = true;
	for(auto v : edges[u]){
		if(v == p)continue;
		if(used[v]){
			int x = u;
			while(x != v){
				is_it_in_cycle[x]=1;
				x=parent[x];
			}is_it_in_cycle[x]=1;
		}else {
			PleaseFindCycles(v,u);
		}
	}
}
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;
	for(int i=0;i<n;i++){
		used[i] = is_it_in_cycle[i] = false;
	}
	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){
		//~ for(int i=0;i<n;i++){
			//~ if(!used[i]){
				//~ PleaseFindCycles(i,i);
			//~ }
		//~ }
		if(number_of_cycles > 1)return 0;
		for(int i=0;i<n;i++){
			if(cyclic[par(i)])ans = max(ans, size_of_node(i));
		}return ans;
	}else assert(false);
	return ans;
}

Compilation message

rings.cpp: In function 'int CountCritical()':
rings.cpp:120:23: warning: 'we_need_it' may be used uninitialized in this function [-Wmaybe-uninitialized]
  120 |   ans += CheckItPlease(we_need_it);
      |          ~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 19 ms 24044 KB Output is correct
3 Correct 17 ms 24044 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 24044 KB Output is correct
7 Correct 15 ms 23916 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 19 ms 24300 KB Output is correct
10 Correct 18 ms 24172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 523 ms 46316 KB Output is correct
2 Correct 1143 ms 60140 KB Output is correct
3 Correct 1215 ms 62860 KB Output is correct
4 Correct 1224 ms 68752 KB Output is correct
5 Correct 1252 ms 68812 KB Output is correct
6 Correct 1190 ms 68000 KB Output is correct
7 Correct 1195 ms 62448 KB Output is correct
8 Correct 2094 ms 66372 KB Output is correct
9 Correct 2232 ms 69772 KB Output is correct
10 Correct 901 ms 67652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 19 ms 24044 KB Output is correct
3 Correct 17 ms 24044 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 24044 KB Output is correct
7 Correct 15 ms 23916 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 19 ms 24300 KB Output is correct
10 Correct 18 ms 24172 KB Output is correct
11 Correct 31 ms 24044 KB Output is correct
12 Correct 26 ms 24300 KB Output is correct
13 Correct 57 ms 24428 KB Output is correct
14 Correct 34 ms 24172 KB Output is correct
15 Correct 42 ms 24300 KB Output is correct
16 Correct 24 ms 24300 KB Output is correct
17 Correct 88 ms 24304 KB Output is correct
18 Correct 28 ms 24608 KB Output is correct
19 Correct 20 ms 24300 KB Output is correct
20 Correct 64 ms 24428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 19 ms 24044 KB Output is correct
3 Correct 17 ms 24044 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 24044 KB Output is correct
7 Correct 15 ms 23916 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 19 ms 24300 KB Output is correct
10 Correct 18 ms 24172 KB Output is correct
11 Correct 31 ms 24044 KB Output is correct
12 Correct 26 ms 24300 KB Output is correct
13 Correct 57 ms 24428 KB Output is correct
14 Correct 34 ms 24172 KB Output is correct
15 Correct 42 ms 24300 KB Output is correct
16 Correct 24 ms 24300 KB Output is correct
17 Correct 88 ms 24304 KB Output is correct
18 Correct 28 ms 24608 KB Output is correct
19 Correct 20 ms 24300 KB Output is correct
20 Correct 64 ms 24428 KB Output is correct
21 Correct 36 ms 25452 KB Output is correct
22 Correct 54 ms 26476 KB Output is correct
23 Correct 58 ms 27116 KB Output is correct
24 Execution timed out 4064 ms 25708 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 19 ms 24044 KB Output is correct
3 Correct 17 ms 24044 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 24044 KB Output is correct
7 Correct 15 ms 23916 KB Output is correct
8 Correct 17 ms 24044 KB Output is correct
9 Correct 19 ms 24300 KB Output is correct
10 Correct 18 ms 24172 KB Output is correct
11 Correct 523 ms 46316 KB Output is correct
12 Correct 1143 ms 60140 KB Output is correct
13 Correct 1215 ms 62860 KB Output is correct
14 Correct 1224 ms 68752 KB Output is correct
15 Correct 1252 ms 68812 KB Output is correct
16 Correct 1190 ms 68000 KB Output is correct
17 Correct 1195 ms 62448 KB Output is correct
18 Correct 2094 ms 66372 KB Output is correct
19 Correct 2232 ms 69772 KB Output is correct
20 Correct 901 ms 67652 KB Output is correct
21 Correct 31 ms 24044 KB Output is correct
22 Correct 26 ms 24300 KB Output is correct
23 Correct 57 ms 24428 KB Output is correct
24 Correct 34 ms 24172 KB Output is correct
25 Correct 42 ms 24300 KB Output is correct
26 Correct 24 ms 24300 KB Output is correct
27 Correct 88 ms 24304 KB Output is correct
28 Correct 28 ms 24608 KB Output is correct
29 Correct 20 ms 24300 KB Output is correct
30 Correct 64 ms 24428 KB Output is correct
31 Correct 36 ms 25452 KB Output is correct
32 Correct 54 ms 26476 KB Output is correct
33 Correct 58 ms 27116 KB Output is correct
34 Execution timed out 4064 ms 25708 KB Time limit exceeded
35 Halted 0 ms 0 KB -