Submission #59236

# Submission time Handle Problem Language Result Execution time Memory
59236 2018-07-21T09:46:59 Z TadijaSebez Parachute rings (IOI12_rings) C++11
52 / 100
4000 ms 82352 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;}
		p[x]=y;
		c[y]+=c[x];
	}
} 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 2 ms 920 KB Output is correct
6 Correct 3 ms 920 KB Output is correct
7 Correct 2 ms 920 KB Output is correct
8 Correct 3 ms 920 KB Output is correct
9 Correct 4 ms 1044 KB Output is correct
10 Correct 6 ms 1044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 403 ms 18900 KB Output is correct
2 Correct 3208 ms 66536 KB Output is correct
3 Execution timed out 4019 ms 82352 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 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 2 ms 920 KB Output is correct
6 Correct 3 ms 920 KB Output is correct
7 Correct 2 ms 920 KB Output is correct
8 Correct 3 ms 920 KB Output is correct
9 Correct 4 ms 1044 KB Output is correct
10 Correct 6 ms 1044 KB Output is correct
11 Correct 4 ms 82352 KB Output is correct
12 Correct 7 ms 82352 KB Output is correct
13 Correct 7 ms 82352 KB Output is correct
14 Correct 6 ms 82352 KB Output is correct
15 Correct 7 ms 82352 KB Output is correct
16 Correct 5 ms 82352 KB Output is correct
17 Correct 7 ms 82352 KB Output is correct
18 Correct 8 ms 82352 KB Output is correct
19 Correct 6 ms 82352 KB Output is correct
20 Correct 7 ms 82352 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 2 ms 920 KB Output is correct
6 Correct 3 ms 920 KB Output is correct
7 Correct 2 ms 920 KB Output is correct
8 Correct 3 ms 920 KB Output is correct
9 Correct 4 ms 1044 KB Output is correct
10 Correct 6 ms 1044 KB Output is correct
11 Correct 4 ms 82352 KB Output is correct
12 Correct 7 ms 82352 KB Output is correct
13 Correct 7 ms 82352 KB Output is correct
14 Correct 6 ms 82352 KB Output is correct
15 Correct 7 ms 82352 KB Output is correct
16 Correct 5 ms 82352 KB Output is correct
17 Correct 7 ms 82352 KB Output is correct
18 Correct 8 ms 82352 KB Output is correct
19 Correct 6 ms 82352 KB Output is correct
20 Correct 7 ms 82352 KB Output is correct
21 Correct 19 ms 82352 KB Output is correct
22 Correct 30 ms 82352 KB Output is correct
23 Correct 43 ms 82352 KB Output is correct
24 Correct 62 ms 82352 KB Output is correct
25 Correct 24 ms 82352 KB Output is correct
26 Correct 55 ms 82352 KB Output is correct
27 Correct 41 ms 82352 KB Output is correct
28 Correct 60 ms 82352 KB Output is correct
29 Correct 48 ms 82352 KB Output is correct
30 Correct 43 ms 82352 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 2 ms 920 KB Output is correct
6 Correct 3 ms 920 KB Output is correct
7 Correct 2 ms 920 KB Output is correct
8 Correct 3 ms 920 KB Output is correct
9 Correct 4 ms 1044 KB Output is correct
10 Correct 6 ms 1044 KB Output is correct
11 Correct 403 ms 18900 KB Output is correct
12 Correct 3208 ms 66536 KB Output is correct
13 Execution timed out 4019 ms 82352 KB Time limit exceeded
14 Halted 0 ms 0 KB -