Submission #94055

# Submission time Handle Problem Language Result Execution time Memory
94055 2019-01-15T08:43:55 Z fjzzq2002 Parachute rings (IOI12_rings) C++14
100 / 100
1891 ms 112472 KB
#include <bits/stdc++.h>
using namespace std;
#define SZ 1234567
#define pb push_back
vector<int> adj[SZ];
int n,stage,ff[SZ],d[4],sz[SZ];
int gf(int x) {return ff[x]?ff[x]=gf(ff[x]):x;}
vector<int> ps;
void uni(int a,int b)
{
	a=gf(a),b=gf(b);
	if(a==b) ps.pb(a);
	else ff[a]=b,sz[b]+=sz[a];
}
void Init(int N_)
{
	n=N_; stage=0;
	for(int i=1;i<=n;++i) sz[i]=1;
}
struct DS
{
int u,good=1;
int ff[SZ],deg[SZ];
int gf(int x) {return ff[x]?ff[x]=gf(ff[x]):x;}
void init(int t)
{
	u=t;
}
void adde(int a,int b)
{
	if(a==u||b==u) return;
	good&=(++deg[a])<=2;
	good&=(++deg[b])<=2;
	a=gf(a),b=gf(b);
	if(a==b) good=0;
	else ff[a]=b;
}
int calc()
{return good;}
}S[4];
void rebuild(int t)
{
	for(int i=0;i<3;++i) S[i].init(adj[t][i]);
	S[3].init(t);
	for(int i=1;i<=n;++i)
		for(auto b:adj[i]) if(i<b)
			for(int k=0;k<4;++k)
				S[k].adde(i,b);
}
void Link(int x,int y) 
{
	++x,++y;
	if(!stage)
	{
		adj[x].pb(y); adj[y].pb(x);
		uni(x,y);
		if(adj[y].size()>=3) swap(x,y);
		if(adj[x].size()>=3)
			stage=1, rebuild(x);
	}
	else
	{
		for(int j=0;j<4;++j)
			S[j].adde(x,y);
	}
}
int CountCritical()
{
	if(!stage)
	{
		if(ps.size()>=2) return 0;
		if(ps.size()==0) return n;
		return sz[gf(ps[0])];
	}
	else
		return S[0].calc()+S[1].calc()+S[2].calc()+S[3].calc();
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 29560 KB Output is correct
2 Correct 29 ms 29688 KB Output is correct
3 Correct 29 ms 29688 KB Output is correct
4 Correct 28 ms 29436 KB Output is correct
5 Correct 30 ms 29560 KB Output is correct
6 Correct 29 ms 29560 KB Output is correct
7 Correct 28 ms 29560 KB Output is correct
8 Correct 30 ms 29560 KB Output is correct
9 Correct 30 ms 29688 KB Output is correct
10 Correct 30 ms 29816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 504 ms 56824 KB Output is correct
2 Correct 972 ms 85400 KB Output is correct
3 Correct 1642 ms 81956 KB Output is correct
4 Correct 1466 ms 82168 KB Output is correct
5 Correct 1534 ms 82128 KB Output is correct
6 Correct 1295 ms 80632 KB Output is correct
7 Correct 1344 ms 81388 KB Output is correct
8 Correct 1567 ms 105080 KB Output is correct
9 Correct 1891 ms 112472 KB Output is correct
10 Correct 874 ms 80332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 29560 KB Output is correct
2 Correct 29 ms 29688 KB Output is correct
3 Correct 29 ms 29688 KB Output is correct
4 Correct 28 ms 29436 KB Output is correct
5 Correct 30 ms 29560 KB Output is correct
6 Correct 29 ms 29560 KB Output is correct
7 Correct 28 ms 29560 KB Output is correct
8 Correct 30 ms 29560 KB Output is correct
9 Correct 30 ms 29688 KB Output is correct
10 Correct 30 ms 29816 KB Output is correct
11 Correct 30 ms 29688 KB Output is correct
12 Correct 29 ms 30240 KB Output is correct
13 Correct 33 ms 30072 KB Output is correct
14 Correct 30 ms 29944 KB Output is correct
15 Correct 27 ms 30312 KB Output is correct
16 Correct 32 ms 29944 KB Output is correct
17 Correct 27 ms 29956 KB Output is correct
18 Correct 32 ms 30332 KB Output is correct
19 Correct 33 ms 29944 KB Output is correct
20 Correct 29 ms 30200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 29560 KB Output is correct
2 Correct 29 ms 29688 KB Output is correct
3 Correct 29 ms 29688 KB Output is correct
4 Correct 28 ms 29436 KB Output is correct
5 Correct 30 ms 29560 KB Output is correct
6 Correct 29 ms 29560 KB Output is correct
7 Correct 28 ms 29560 KB Output is correct
8 Correct 30 ms 29560 KB Output is correct
9 Correct 30 ms 29688 KB Output is correct
10 Correct 30 ms 29816 KB Output is correct
11 Correct 30 ms 29688 KB Output is correct
12 Correct 29 ms 30240 KB Output is correct
13 Correct 33 ms 30072 KB Output is correct
14 Correct 30 ms 29944 KB Output is correct
15 Correct 27 ms 30312 KB Output is correct
16 Correct 32 ms 29944 KB Output is correct
17 Correct 27 ms 29956 KB Output is correct
18 Correct 32 ms 30332 KB Output is correct
19 Correct 33 ms 29944 KB Output is correct
20 Correct 29 ms 30200 KB Output is correct
21 Correct 41 ms 31224 KB Output is correct
22 Correct 59 ms 32248 KB Output is correct
23 Correct 61 ms 33016 KB Output is correct
24 Correct 66 ms 33656 KB Output is correct
25 Correct 42 ms 33272 KB Output is correct
26 Correct 62 ms 34168 KB Output is correct
27 Correct 71 ms 33912 KB Output is correct
28 Correct 106 ms 34072 KB Output is correct
29 Correct 50 ms 34296 KB Output is correct
30 Correct 78 ms 34424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 29560 KB Output is correct
2 Correct 29 ms 29688 KB Output is correct
3 Correct 29 ms 29688 KB Output is correct
4 Correct 28 ms 29436 KB Output is correct
5 Correct 30 ms 29560 KB Output is correct
6 Correct 29 ms 29560 KB Output is correct
7 Correct 28 ms 29560 KB Output is correct
8 Correct 30 ms 29560 KB Output is correct
9 Correct 30 ms 29688 KB Output is correct
10 Correct 30 ms 29816 KB Output is correct
11 Correct 504 ms 56824 KB Output is correct
12 Correct 972 ms 85400 KB Output is correct
13 Correct 1642 ms 81956 KB Output is correct
14 Correct 1466 ms 82168 KB Output is correct
15 Correct 1534 ms 82128 KB Output is correct
16 Correct 1295 ms 80632 KB Output is correct
17 Correct 1344 ms 81388 KB Output is correct
18 Correct 1567 ms 105080 KB Output is correct
19 Correct 1891 ms 112472 KB Output is correct
20 Correct 874 ms 80332 KB Output is correct
21 Correct 30 ms 29688 KB Output is correct
22 Correct 29 ms 30240 KB Output is correct
23 Correct 33 ms 30072 KB Output is correct
24 Correct 30 ms 29944 KB Output is correct
25 Correct 27 ms 30312 KB Output is correct
26 Correct 32 ms 29944 KB Output is correct
27 Correct 27 ms 29956 KB Output is correct
28 Correct 32 ms 30332 KB Output is correct
29 Correct 33 ms 29944 KB Output is correct
30 Correct 29 ms 30200 KB Output is correct
31 Correct 41 ms 31224 KB Output is correct
32 Correct 59 ms 32248 KB Output is correct
33 Correct 61 ms 33016 KB Output is correct
34 Correct 66 ms 33656 KB Output is correct
35 Correct 42 ms 33272 KB Output is correct
36 Correct 62 ms 34168 KB Output is correct
37 Correct 71 ms 33912 KB Output is correct
38 Correct 106 ms 34072 KB Output is correct
39 Correct 50 ms 34296 KB Output is correct
40 Correct 78 ms 34424 KB Output is correct
41 Correct 216 ms 45532 KB Output is correct
42 Correct 525 ms 81672 KB Output is correct
43 Correct 263 ms 67320 KB Output is correct
44 Correct 649 ms 78072 KB Output is correct
45 Correct 826 ms 79608 KB Output is correct
46 Correct 707 ms 73976 KB Output is correct
47 Correct 972 ms 74872 KB Output is correct
48 Correct 454 ms 77048 KB Output is correct
49 Correct 823 ms 73464 KB Output is correct
50 Correct 910 ms 73028 KB Output is correct
51 Correct 320 ms 64376 KB Output is correct
52 Correct 523 ms 69112 KB Output is correct
53 Correct 427 ms 75808 KB Output is correct
54 Correct 1057 ms 91696 KB Output is correct
55 Correct 1022 ms 76564 KB Output is correct