Submission #986343

# Submission time Handle Problem Language Result Execution time Memory
986343 2024-05-20T11:02:27 Z Pyqe Parachute rings (IOI12_rings) C++17
100 / 100
1678 ms 164104 KB
#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define fr first
#define sc second

long long n,m=0,d=0,nn=1,dg[5][1000069],dsu[5][1000069],e[5]={-1},c[5],c2[5],z;
pair<long long,long long> ed[1000069];
vector<long long> al[1000069];
bitset<1000069> vtd;
bool r0=0;

long long fd(long long y,long long x)
{
	if(dsu[y][x]!=x)
	{
		dsu[y][x]=fd(y,dsu[y][x]);
	}
	return dsu[y][x];
}

void bd(long long x)
{
	long long i,ii,k,l;
	
	e[nn]=x;
	c[nn]=0;
	c2[nn]=0;
	for(i=1;i<=n;i++)
	{
		dg[nn][i]=0;
		dsu[nn][i]=i;
	}
	for(i=1;i<m;i++)
	{
		k=ed[i].fr;
		l=ed[i].sc;
		if(k!=x&&l!=x)
		{
			for(ii=0;ii<2;ii++)
			{
				dg[nn][k]++;
				c[nn]+=dg[nn][k]>=3;
				swap(k,l);
			}
			c2[nn]+=fd(nn,k)==fd(nn,l);
			dsu[nn][fd(nn,l)]=fd(nn,k);
		}
	}
	nn++;
}

void dfs(long long x,long long y)
{
	long long i,sz=al[x].size(),l;
	
	vtd[x]=1;
	if(x==y)
	{
		d++;
		r0=1;
		return;
	}
	for(i=0;i<sz;i++)
	{
		l=al[x][i];
		if(!vtd[l])
		{
			dfs(l,y);
			if(r0)
			{
				d++;
				return;
			}
		}
	}
}

void Init(int on)
{
	long long i;
	
	n=on;
	z=n;
	for(i=1;i<=n;i++)
	{
		dsu[0][i]=i;
	}
}

void Link(int x,int y)
{
	long long i,ii;
	
	x++;
	y++;
	m++;
	ed[m]={x,y};
	z=0;
	for(i=0;i<nn;i++)
	{
		if(x!=e[i]&&y!=e[i])
		{
			for(ii=0;ii<2;ii++)
			{
				dg[i][x]++;
				if(dg[i][x]>=3)
				{
					c[i]++;
					if(!i&&dg[0][e[1]]<=3)
					{
						if(dg[i][x]==3)
						{
							if(nn<5)
							{
								bd(x);
								bd(y);
								bd(al[x][0]);
								bd(al[x][1]);
							}
						}
						else
						{
							nn=1;
							bd(x);
						}
					}
				}
				swap(x,y);
			}
			if(fd(i,x)==fd(i,y))
			{
				c2[i]++;
				if(!i&&c2[i]==1)
				{
					dfs(x,y);
				}
			}
			dsu[i][fd(i,y)]=fd(i,x);
			if(!i)
			{
				al[x].push_back(y);
				al[y].push_back(x);
			}
		}
		if(!c[i])
		{
			if(!i)
			{
				if(!c2[i])
				{
					z+=n;
				}
				else if(c2[i]==1)
				{
					z+=d;
				}
			}
			else
			{
				z+=!c2[i];
			}
		}
	}
}

int CountCritical()
{
	return z;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 11 ms 43800 KB Output is correct
3 Correct 10 ms 44020 KB Output is correct
4 Correct 6 ms 27244 KB Output is correct
5 Correct 7 ms 27228 KB Output is correct
6 Correct 7 ms 27400 KB Output is correct
7 Correct 8 ms 43692 KB Output is correct
8 Correct 7 ms 27412 KB Output is correct
9 Correct 10 ms 43864 KB Output is correct
10 Correct 10 ms 43868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 274 ms 66644 KB Output is correct
2 Correct 1000 ms 149392 KB Output is correct
3 Correct 1678 ms 164104 KB Output is correct
4 Correct 693 ms 100252 KB Output is correct
5 Correct 677 ms 101204 KB Output is correct
6 Correct 799 ms 121496 KB Output is correct
7 Correct 893 ms 161964 KB Output is correct
8 Correct 993 ms 158540 KB Output is correct
9 Correct 1097 ms 162284 KB Output is correct
10 Correct 466 ms 98372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 11 ms 43800 KB Output is correct
3 Correct 10 ms 44020 KB Output is correct
4 Correct 6 ms 27244 KB Output is correct
5 Correct 7 ms 27228 KB Output is correct
6 Correct 7 ms 27400 KB Output is correct
7 Correct 8 ms 43692 KB Output is correct
8 Correct 7 ms 27412 KB Output is correct
9 Correct 10 ms 43864 KB Output is correct
10 Correct 10 ms 43868 KB Output is correct
11 Correct 10 ms 43864 KB Output is correct
12 Correct 12 ms 44072 KB Output is correct
13 Correct 15 ms 44124 KB Output is correct
14 Correct 11 ms 43868 KB Output is correct
15 Correct 11 ms 45916 KB Output is correct
16 Correct 8 ms 27640 KB Output is correct
17 Correct 11 ms 44128 KB Output is correct
18 Correct 13 ms 46172 KB Output is correct
19 Correct 9 ms 27740 KB Output is correct
20 Correct 12 ms 44124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 11 ms 43800 KB Output is correct
3 Correct 10 ms 44020 KB Output is correct
4 Correct 6 ms 27244 KB Output is correct
5 Correct 7 ms 27228 KB Output is correct
6 Correct 7 ms 27400 KB Output is correct
7 Correct 8 ms 43692 KB Output is correct
8 Correct 7 ms 27412 KB Output is correct
9 Correct 10 ms 43864 KB Output is correct
10 Correct 10 ms 43868 KB Output is correct
11 Correct 10 ms 43864 KB Output is correct
12 Correct 12 ms 44072 KB Output is correct
13 Correct 15 ms 44124 KB Output is correct
14 Correct 11 ms 43868 KB Output is correct
15 Correct 11 ms 45916 KB Output is correct
16 Correct 8 ms 27640 KB Output is correct
17 Correct 11 ms 44128 KB Output is correct
18 Correct 13 ms 46172 KB Output is correct
19 Correct 9 ms 27740 KB Output is correct
20 Correct 12 ms 44124 KB Output is correct
21 Correct 20 ms 29108 KB Output is correct
22 Correct 26 ms 30044 KB Output is correct
23 Correct 32 ms 30788 KB Output is correct
24 Correct 46 ms 55124 KB Output is correct
25 Correct 19 ms 53080 KB Output is correct
26 Correct 45 ms 55460 KB Output is correct
27 Correct 34 ms 33692 KB Output is correct
28 Correct 66 ms 58248 KB Output is correct
29 Correct 34 ms 54612 KB Output is correct
30 Correct 37 ms 34840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 11 ms 43800 KB Output is correct
3 Correct 10 ms 44020 KB Output is correct
4 Correct 6 ms 27244 KB Output is correct
5 Correct 7 ms 27228 KB Output is correct
6 Correct 7 ms 27400 KB Output is correct
7 Correct 8 ms 43692 KB Output is correct
8 Correct 7 ms 27412 KB Output is correct
9 Correct 10 ms 43864 KB Output is correct
10 Correct 10 ms 43868 KB Output is correct
11 Correct 274 ms 66644 KB Output is correct
12 Correct 1000 ms 149392 KB Output is correct
13 Correct 1678 ms 164104 KB Output is correct
14 Correct 693 ms 100252 KB Output is correct
15 Correct 677 ms 101204 KB Output is correct
16 Correct 799 ms 121496 KB Output is correct
17 Correct 893 ms 161964 KB Output is correct
18 Correct 993 ms 158540 KB Output is correct
19 Correct 1097 ms 162284 KB Output is correct
20 Correct 466 ms 98372 KB Output is correct
21 Correct 10 ms 43864 KB Output is correct
22 Correct 12 ms 44072 KB Output is correct
23 Correct 15 ms 44124 KB Output is correct
24 Correct 11 ms 43868 KB Output is correct
25 Correct 11 ms 45916 KB Output is correct
26 Correct 8 ms 27640 KB Output is correct
27 Correct 11 ms 44128 KB Output is correct
28 Correct 13 ms 46172 KB Output is correct
29 Correct 9 ms 27740 KB Output is correct
30 Correct 12 ms 44124 KB Output is correct
31 Correct 20 ms 29108 KB Output is correct
32 Correct 26 ms 30044 KB Output is correct
33 Correct 32 ms 30788 KB Output is correct
34 Correct 46 ms 55124 KB Output is correct
35 Correct 19 ms 53080 KB Output is correct
36 Correct 45 ms 55460 KB Output is correct
37 Correct 34 ms 33692 KB Output is correct
38 Correct 66 ms 58248 KB Output is correct
39 Correct 34 ms 54612 KB Output is correct
40 Correct 37 ms 34840 KB Output is correct
41 Correct 144 ms 47188 KB Output is correct
42 Correct 394 ms 130612 KB Output is correct
43 Correct 214 ms 109392 KB Output is correct
44 Correct 801 ms 156736 KB Output is correct
45 Correct 1040 ms 147408 KB Output is correct
46 Correct 435 ms 90196 KB Output is correct
47 Correct 695 ms 104536 KB Output is correct
48 Correct 400 ms 130972 KB Output is correct
49 Correct 424 ms 87440 KB Output is correct
50 Correct 461 ms 87012 KB Output is correct
51 Correct 261 ms 112268 KB Output is correct
52 Correct 680 ms 146140 KB Output is correct
53 Correct 396 ms 133348 KB Output is correct
54 Correct 1031 ms 150852 KB Output is correct
55 Correct 1251 ms 156404 KB Output is correct