Submission #59237

# Submission time Handle Problem Language Result Execution time Memory
59237 2018-07-21T09:54:42 Z TadijaSebez Parachute rings (IOI12_rings) C++11
100 / 100
3522 ms 82820 KB
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
const int N=1000050;
int n;
struct DSU
{
	int p[N],c[N],deg[N];
	int cyc,my,sz;
	bool ok;
	DSU(){}
	void init(int x)
	{
		my=x;cyc=sz=0;ok=1;
		for(int i=0;i<n;i++) p[i]=i,c[i]=1,deg[i]=0;
	}
	int Find(int x){ return x==p[x]?x:p[x]=Find(p[x]);}
	void Union(int x, int y)
	{
		if(x==my || y==my) return;
		deg[x]++;deg[y]++;
		if(deg[x]>2 || deg[y]>2) ok=0;
		x=Find(x);y=Find(y);
		if(x==y){ cyc++,sz=c[x],ok=0;return;}
		if(c[y]>c[x])
		{
			p[x]=y;
			c[y]+=c[x];
		}
		else
		{
			p[y]=x;
			c[x]+=c[y];
		}
	}
} Base,Try[4];
int E[N][3];
int esz;
pair<int,int> edges[N];
int deg[N],sz;
bool mod;
void Init(int m){ n=m;Base.init(-1);}
void Push()
{
	for(int i=0;i<esz;i++)
	{
		for(int j=0;j<sz;j++)
		{
			Try[j].Union(edges[i].first,edges[i].second);
		}
	}
}
void Link(int a, int b)
{
	if(deg[a]<3) E[a][deg[a]]=b;
	deg[a]++;
	if(deg[b]<3) E[b][deg[b]]=a;
	deg[b]++;
	Base.Union(a,b);
	edges[esz++]=mp(a,b);
	if(mod)
	{
		for(int i=0;i<sz;i++) Try[i].Union(a,b);
		return;
	}
	if(deg[a]>2)
	{
		sz=4;
		Try[0].init(a);
		for(int i=0;i<3;i++) Try[i+1].init(E[a][i]);
		Push();
		mod=1;
		return;
	}
	if(deg[b]>2)
	{
		sz=4;
		Try[0].init(b);
		for(int i=0;i<3;i++) Try[i+1].init(E[b][i]);
		Push();
		mod=1;
		return;
	}
}
int CountCritical()
{
	if(mod)
	{
		int ans=0;
		for(int i=0;i<sz;i++) if(Try[i].ok) ans++;
		return ans;
	}
	if(Base.cyc>1) return 0;
	if(Base.cyc==1) return Base.sz;
	return n;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 884 KB Output is correct
3 Correct 4 ms 920 KB Output is correct
4 Correct 2 ms 920 KB Output is correct
5 Correct 3 ms 920 KB Output is correct
6 Correct 3 ms 920 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 4 ms 1132 KB Output is correct
10 Correct 4 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 345 ms 18924 KB Output is correct
2 Correct 2913 ms 66576 KB Output is correct
3 Correct 3201 ms 82540 KB Output is correct
4 Correct 1065 ms 82540 KB Output is correct
5 Correct 1096 ms 82540 KB Output is correct
6 Correct 1109 ms 82540 KB Output is correct
7 Correct 3090 ms 82540 KB Output is correct
8 Correct 3318 ms 82540 KB Output is correct
9 Correct 3522 ms 82820 KB Output is correct
10 Correct 713 ms 82820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 884 KB Output is correct
3 Correct 4 ms 920 KB Output is correct
4 Correct 2 ms 920 KB Output is correct
5 Correct 3 ms 920 KB Output is correct
6 Correct 3 ms 920 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 4 ms 1132 KB Output is correct
10 Correct 4 ms 1132 KB Output is correct
11 Correct 4 ms 82820 KB Output is correct
12 Correct 6 ms 82820 KB Output is correct
13 Correct 6 ms 82820 KB Output is correct
14 Correct 5 ms 82820 KB Output is correct
15 Correct 6 ms 82820 KB Output is correct
16 Correct 5 ms 82820 KB Output is correct
17 Correct 6 ms 82820 KB Output is correct
18 Correct 7 ms 82820 KB Output is correct
19 Correct 5 ms 82820 KB Output is correct
20 Correct 7 ms 82820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 884 KB Output is correct
3 Correct 4 ms 920 KB Output is correct
4 Correct 2 ms 920 KB Output is correct
5 Correct 3 ms 920 KB Output is correct
6 Correct 3 ms 920 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 4 ms 1132 KB Output is correct
10 Correct 4 ms 1132 KB Output is correct
11 Correct 4 ms 82820 KB Output is correct
12 Correct 6 ms 82820 KB Output is correct
13 Correct 6 ms 82820 KB Output is correct
14 Correct 5 ms 82820 KB Output is correct
15 Correct 6 ms 82820 KB Output is correct
16 Correct 5 ms 82820 KB Output is correct
17 Correct 6 ms 82820 KB Output is correct
18 Correct 7 ms 82820 KB Output is correct
19 Correct 5 ms 82820 KB Output is correct
20 Correct 7 ms 82820 KB Output is correct
21 Correct 20 ms 82820 KB Output is correct
22 Correct 30 ms 82820 KB Output is correct
23 Correct 36 ms 82820 KB Output is correct
24 Correct 53 ms 82820 KB Output is correct
25 Correct 25 ms 82820 KB Output is correct
26 Correct 51 ms 82820 KB Output is correct
27 Correct 39 ms 82820 KB Output is correct
28 Correct 62 ms 82820 KB Output is correct
29 Correct 48 ms 82820 KB Output is correct
30 Correct 45 ms 82820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 884 KB Output is correct
3 Correct 4 ms 920 KB Output is correct
4 Correct 2 ms 920 KB Output is correct
5 Correct 3 ms 920 KB Output is correct
6 Correct 3 ms 920 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 4 ms 1132 KB Output is correct
10 Correct 4 ms 1132 KB Output is correct
11 Correct 345 ms 18924 KB Output is correct
12 Correct 2913 ms 66576 KB Output is correct
13 Correct 3201 ms 82540 KB Output is correct
14 Correct 1065 ms 82540 KB Output is correct
15 Correct 1096 ms 82540 KB Output is correct
16 Correct 1109 ms 82540 KB Output is correct
17 Correct 3090 ms 82540 KB Output is correct
18 Correct 3318 ms 82540 KB Output is correct
19 Correct 3522 ms 82820 KB Output is correct
20 Correct 713 ms 82820 KB Output is correct
21 Correct 4 ms 82820 KB Output is correct
22 Correct 6 ms 82820 KB Output is correct
23 Correct 6 ms 82820 KB Output is correct
24 Correct 5 ms 82820 KB Output is correct
25 Correct 6 ms 82820 KB Output is correct
26 Correct 5 ms 82820 KB Output is correct
27 Correct 6 ms 82820 KB Output is correct
28 Correct 7 ms 82820 KB Output is correct
29 Correct 5 ms 82820 KB Output is correct
30 Correct 7 ms 82820 KB Output is correct
31 Correct 20 ms 82820 KB Output is correct
32 Correct 30 ms 82820 KB Output is correct
33 Correct 36 ms 82820 KB Output is correct
34 Correct 53 ms 82820 KB Output is correct
35 Correct 25 ms 82820 KB Output is correct
36 Correct 51 ms 82820 KB Output is correct
37 Correct 39 ms 82820 KB Output is correct
38 Correct 62 ms 82820 KB Output is correct
39 Correct 48 ms 82820 KB Output is correct
40 Correct 45 ms 82820 KB Output is correct
41 Correct 212 ms 82820 KB Output is correct
42 Correct 1316 ms 82820 KB Output is correct
43 Correct 474 ms 82820 KB Output is correct
44 Correct 1932 ms 82820 KB Output is correct
45 Correct 2093 ms 82820 KB Output is correct
46 Correct 729 ms 82820 KB Output is correct
47 Correct 881 ms 82820 KB Output is correct
48 Correct 1456 ms 82820 KB Output is correct
49 Correct 755 ms 82820 KB Output is correct
50 Correct 766 ms 82820 KB Output is correct
51 Correct 668 ms 82820 KB Output is correct
52 Correct 1730 ms 82820 KB Output is correct
53 Correct 1628 ms 82820 KB Output is correct
54 Correct 3051 ms 82820 KB Output is correct
55 Correct 3490 ms 82820 KB Output is correct