Submission #350697

# Submission time Handle Problem Language Result Execution time Memory
350697 2021-01-19T07:34:16 Z Kerim Parachute rings (IOI12_rings) C++17
100 / 100
1774 ms 124436 KB
#include "bits/stdc++.h"
#define MAXN 1000009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
class dsu{
	public:
	int ata[MAXN],sz[MAXN];
	dsu(){}
	void init(int x){
		for(int i=1;i<=x;i++)
			ata[i]=i,sz[i]=1;	
	}
	int tap(int x){
		if(ata[x]==x)
			return x;
		return ata[x]=tap(ata[x]);	
	}
	void merge(int x,int y){
		if((x=tap(x))==(y=tap(y)))
			return;
		if(sz[x]>sz[y])
			swap(x,y);
		ata[y]=x;
		sz[x]+=sz[y];
	}
}D[5],T;
bool ok=0;
int H[5],Dg[5][MAXN],n,q,len_cycle=0;
int deg[MAXN],cycle=0,res[5];
vector<int>adj[MAXN];
void _add(int x,int y){
	for(int i=0;i<4;i++){
		if(!res[i])
			continue;
		if(H[i]==x or H[i]==y)
			continue;
		Dg[i][x]++;Dg[i][y]++;	
		if(Dg[i][x]==3 or Dg[i][y]==3){
			res[i]=0;
			continue;
		}
		if(D[i].tap(x)==D[i].tap(y)){
			res[i]=0;
			continue;
		}
		D[i].merge(x,y);
	}
}
void build(int x){
	ok=1;
	H[0]=x;
	H[1]=adj[x][0];
	H[2]=adj[x][1];
	H[3]=adj[x][2];
	for(int i=0;i<4;i++){
		D[i].init(n);
		res[i]=1;
	}
	for(int i=1;i<=n;i++)
		tr(it,adj[i])
			if(i<*it)
				_add(*it,i);
}
int dfs(int node,int nd,int pr,int num){
	if(node==nd and ~pr)
		return num;int mx=0;
	for(int i=0;i<int(adj[nd].size());i++){
		int to=adj[nd][i];
		if(to==pr)
			continue;
		umax(mx,dfs(node,to,nd,num+1));
	}
	return mx;
}
void Link(int x,int y){x++;y++;
	if(!ok){
		adj[x].pb(y);
		adj[y].pb(x);
		deg[x]++;deg[y]++;
		if(deg[x]==3){
			build(x);
			return;
		}
		if(deg[y]==3){
			build(y);
			return;
		}
		if(T.tap(x)==T.tap(y)){
			if(!cycle)
				len_cycle=dfs(x,x,-1,0);cycle++;	
			return;
		}
		T.merge(x,y);
	}
	else
		_add(x,y);
}
int CountCritical(){
	if(ok){
		int sum=0;
		for(int i=0;i<4;i++)sum+=res[i];
		return sum;	
	}
	if(!cycle)
		return n;
	if(cycle==1)
		return len_cycle;
	return 0;	
}
void Init(int szx){
	memset(deg,0,sizeof(deg));
	n=szx;T.init(szx);
}

Compilation message

rings.cpp: In function 'int dfs(int, int, int, int)':
rings.cpp:79:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   79 |  if(node==nd and ~pr)
      |  ^~
rings.cpp:80:14: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   80 |   return num;int mx=0;
      |              ^~~
rings.cpp: In function 'void Link(int, int)':
rings.cpp:103:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  103 |    if(!cycle)
      |    ^~
rings.cpp:104:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  104 |     len_cycle=dfs(x,x,-1,0);cycle++;
      |                             ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 27756 KB Output is correct
2 Correct 21 ms 28140 KB Output is correct
3 Correct 22 ms 28268 KB Output is correct
4 Correct 22 ms 27756 KB Output is correct
5 Correct 22 ms 28012 KB Output is correct
6 Correct 27 ms 28268 KB Output is correct
7 Correct 20 ms 28140 KB Output is correct
8 Correct 23 ms 28012 KB Output is correct
9 Correct 25 ms 28268 KB Output is correct
10 Correct 23 ms 28268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 521 ms 54572 KB Output is correct
2 Correct 833 ms 95536 KB Output is correct
3 Correct 318 ms 93932 KB Output is correct
4 Correct 1233 ms 77804 KB Output is correct
5 Correct 1232 ms 79852 KB Output is correct
6 Correct 1480 ms 115436 KB Output is correct
7 Correct 307 ms 94828 KB Output is correct
8 Correct 1507 ms 116804 KB Output is correct
9 Correct 1774 ms 124436 KB Output is correct
10 Correct 916 ms 77932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 27756 KB Output is correct
2 Correct 21 ms 28140 KB Output is correct
3 Correct 22 ms 28268 KB Output is correct
4 Correct 22 ms 27756 KB Output is correct
5 Correct 22 ms 28012 KB Output is correct
6 Correct 27 ms 28268 KB Output is correct
7 Correct 20 ms 28140 KB Output is correct
8 Correct 23 ms 28012 KB Output is correct
9 Correct 25 ms 28268 KB Output is correct
10 Correct 23 ms 28268 KB Output is correct
11 Correct 21 ms 28268 KB Output is correct
12 Correct 25 ms 28780 KB Output is correct
13 Correct 23 ms 28652 KB Output is correct
14 Correct 21 ms 28524 KB Output is correct
15 Correct 22 ms 28908 KB Output is correct
16 Correct 25 ms 28268 KB Output is correct
17 Correct 22 ms 28524 KB Output is correct
18 Correct 23 ms 29164 KB Output is correct
19 Correct 26 ms 28396 KB Output is correct
20 Correct 24 ms 28780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 27756 KB Output is correct
2 Correct 21 ms 28140 KB Output is correct
3 Correct 22 ms 28268 KB Output is correct
4 Correct 22 ms 27756 KB Output is correct
5 Correct 22 ms 28012 KB Output is correct
6 Correct 27 ms 28268 KB Output is correct
7 Correct 20 ms 28140 KB Output is correct
8 Correct 23 ms 28012 KB Output is correct
9 Correct 25 ms 28268 KB Output is correct
10 Correct 23 ms 28268 KB Output is correct
11 Correct 21 ms 28268 KB Output is correct
12 Correct 25 ms 28780 KB Output is correct
13 Correct 23 ms 28652 KB Output is correct
14 Correct 21 ms 28524 KB Output is correct
15 Correct 22 ms 28908 KB Output is correct
16 Correct 25 ms 28268 KB Output is correct
17 Correct 22 ms 28524 KB Output is correct
18 Correct 23 ms 29164 KB Output is correct
19 Correct 26 ms 28396 KB Output is correct
20 Correct 24 ms 28780 KB Output is correct
21 Correct 41 ms 29548 KB Output is correct
22 Correct 51 ms 30572 KB Output is correct
23 Correct 63 ms 31340 KB Output is correct
24 Correct 51 ms 32828 KB Output is correct
25 Correct 39 ms 32748 KB Output is correct
26 Correct 55 ms 34028 KB Output is correct
27 Correct 86 ms 32236 KB Output is correct
28 Correct 49 ms 33772 KB Output is correct
29 Correct 56 ms 34284 KB Output is correct
30 Correct 92 ms 33772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 27756 KB Output is correct
2 Correct 21 ms 28140 KB Output is correct
3 Correct 22 ms 28268 KB Output is correct
4 Correct 22 ms 27756 KB Output is correct
5 Correct 22 ms 28012 KB Output is correct
6 Correct 27 ms 28268 KB Output is correct
7 Correct 20 ms 28140 KB Output is correct
8 Correct 23 ms 28012 KB Output is correct
9 Correct 25 ms 28268 KB Output is correct
10 Correct 23 ms 28268 KB Output is correct
11 Correct 521 ms 54572 KB Output is correct
12 Correct 833 ms 95536 KB Output is correct
13 Correct 318 ms 93932 KB Output is correct
14 Correct 1233 ms 77804 KB Output is correct
15 Correct 1232 ms 79852 KB Output is correct
16 Correct 1480 ms 115436 KB Output is correct
17 Correct 307 ms 94828 KB Output is correct
18 Correct 1507 ms 116804 KB Output is correct
19 Correct 1774 ms 124436 KB Output is correct
20 Correct 916 ms 77932 KB Output is correct
21 Correct 21 ms 28268 KB Output is correct
22 Correct 25 ms 28780 KB Output is correct
23 Correct 23 ms 28652 KB Output is correct
24 Correct 21 ms 28524 KB Output is correct
25 Correct 22 ms 28908 KB Output is correct
26 Correct 25 ms 28268 KB Output is correct
27 Correct 22 ms 28524 KB Output is correct
28 Correct 23 ms 29164 KB Output is correct
29 Correct 26 ms 28396 KB Output is correct
30 Correct 24 ms 28780 KB Output is correct
31 Correct 41 ms 29548 KB Output is correct
32 Correct 51 ms 30572 KB Output is correct
33 Correct 63 ms 31340 KB Output is correct
34 Correct 51 ms 32828 KB Output is correct
35 Correct 39 ms 32748 KB Output is correct
36 Correct 55 ms 34028 KB Output is correct
37 Correct 86 ms 32236 KB Output is correct
38 Correct 49 ms 33772 KB Output is correct
39 Correct 56 ms 34284 KB Output is correct
40 Correct 92 ms 33772 KB Output is correct
41 Correct 257 ms 43884 KB Output is correct
42 Correct 787 ms 93324 KB Output is correct
43 Correct 261 ms 74092 KB Output is correct
44 Correct 310 ms 87148 KB Output is correct
45 Correct 443 ms 93548 KB Output is correct
46 Correct 832 ms 69612 KB Output is correct
47 Correct 1228 ms 92524 KB Output is correct
48 Correct 305 ms 91208 KB Output is correct
49 Correct 794 ms 71392 KB Output is correct
50 Correct 835 ms 70876 KB Output is correct
51 Correct 258 ms 75116 KB Output is correct
52 Correct 305 ms 78572 KB Output is correct
53 Correct 267 ms 90092 KB Output is correct
54 Correct 1119 ms 100076 KB Output is correct
55 Correct 563 ms 84972 KB Output is correct