Submission #1015565

# Submission time Handle Problem Language Result Execution time Memory
1015565 2024-07-06T14:19:07 Z parsadox2 Parachute rings (IOI12_rings) C++17
100 / 100
1222 ms 231880 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;
int ans , n , deg[N];
bool flg;
vector <int> adj[N];

struct Graph{
	int vert , par[N] , d[N];
	bool ok , marked[N];
	vector <int> all[N];
	void Dfs(int v , int p = -1)
	{
		marked[v] = true;
		par[v] = (p == -1 ? v : par[p]);
		int D = (p != -1);
		for(auto u : adj[v])  if(u != vert)
		{
			if(!marked[u])
			{
				D++;
				Dfs(u , v);
			}
			else if(u != p)
				ok = false;
		}
		if(D > 2)
			ok = false;
		d[v] = D;
	}
	int root(int v)
	{
		return (par[v] == v ? v : par[v] = root(par[v]));
	}
	void Build()
	{
		ok = true;
		marked[vert] = true;
		for(int i = 0 ; i < n ; i++)  if(!marked[i])
			Dfs(i);
	}
	void Add(int a , int b)
	{
		if(a == vert || b == vert)
			return;
		int ra = root(a) , rb = root(b);
		if(d[a] > 1 || d[b] > 1 || ra == rb)
		{
			ok = false;
			return;
		}
		par[rb] = ra;
		d[a]++;
		d[b]++;
	}
} graph[5];

struct DSU{
	int sz[N] , par[N];
	void Build()
	{
		for(int i = 0 ; i < n ; i++)
		{
			par[i] = i;
			sz[i] = 1;
		}
	}
	int root(int v)
	{
		return (par[v] == v ? v : par[v] = root(par[v]));
	}
	void Merge(int a , int b)
	{
		deg[a]++;  deg[b]++;
		adj[a].push_back(b);
		adj[b].push_back(a);
		if(deg[a] < deg[b])
			swap(a , b);
		int ra = root(a) , rb = root(b);
		//cout << a << " --- " << b << " " << ra << " " << rb << endl;
		if(deg[a] == 3)
		{
			graph[0].vert = a;
			for(int i = 1 ; i <= 3 ; i++)
				graph[i].vert = adj[a][i - 1];
			for(int i = 0 ; i < 4 ; i++)
				graph[i].Build();
			flg = true;
			return;
		}
		if(ra == rb)
		{
			ans = (ans == n ? sz[ra] : 0);
			return;
		}
		par[rb] = ra;
		sz[ra] += sz[rb];
	}
} dsu;

void Init(int x)
{
	n = x;
	ans = x;
	dsu.Build();
}

void Link(int a , int b)
{
	if(!flg)
		dsu.Merge(a , b);
	else
	{
		for(int i = 0 ; i < 4 ; i++)
			graph[i].Add(a , b);
	}
}

int CountCritical()
{
	if(!flg)
		return ans;
	else
	{
		int cnt = 0;
		for(int i = 0 ; i < 4 ; i++)
			cnt += graph[i].ok;
		return cnt;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 141648 KB Output is correct
2 Correct 54 ms 141860 KB Output is correct
3 Correct 57 ms 141952 KB Output is correct
4 Correct 56 ms 141648 KB Output is correct
5 Correct 54 ms 141872 KB Output is correct
6 Correct 56 ms 141912 KB Output is correct
7 Correct 54 ms 141904 KB Output is correct
8 Correct 54 ms 141856 KB Output is correct
9 Correct 56 ms 142096 KB Output is correct
10 Correct 54 ms 142188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 170832 KB Output is correct
2 Correct 453 ms 203600 KB Output is correct
3 Correct 388 ms 201556 KB Output is correct
4 Correct 578 ms 197732 KB Output is correct
5 Correct 609 ms 197764 KB Output is correct
6 Correct 573 ms 196248 KB Output is correct
7 Correct 354 ms 200792 KB Output is correct
8 Correct 1043 ms 224080 KB Output is correct
9 Correct 1222 ms 231880 KB Output is correct
10 Correct 408 ms 195156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 141648 KB Output is correct
2 Correct 54 ms 141860 KB Output is correct
3 Correct 57 ms 141952 KB Output is correct
4 Correct 56 ms 141648 KB Output is correct
5 Correct 54 ms 141872 KB Output is correct
6 Correct 56 ms 141912 KB Output is correct
7 Correct 54 ms 141904 KB Output is correct
8 Correct 54 ms 141856 KB Output is correct
9 Correct 56 ms 142096 KB Output is correct
10 Correct 54 ms 142188 KB Output is correct
11 Correct 60 ms 142164 KB Output is correct
12 Correct 59 ms 142416 KB Output is correct
13 Correct 58 ms 142508 KB Output is correct
14 Correct 60 ms 142164 KB Output is correct
15 Correct 57 ms 142720 KB Output is correct
16 Correct 62 ms 141996 KB Output is correct
17 Correct 58 ms 142224 KB Output is correct
18 Correct 58 ms 142692 KB Output is correct
19 Correct 55 ms 142156 KB Output is correct
20 Correct 56 ms 142448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 141648 KB Output is correct
2 Correct 54 ms 141860 KB Output is correct
3 Correct 57 ms 141952 KB Output is correct
4 Correct 56 ms 141648 KB Output is correct
5 Correct 54 ms 141872 KB Output is correct
6 Correct 56 ms 141912 KB Output is correct
7 Correct 54 ms 141904 KB Output is correct
8 Correct 54 ms 141856 KB Output is correct
9 Correct 56 ms 142096 KB Output is correct
10 Correct 54 ms 142188 KB Output is correct
11 Correct 60 ms 142164 KB Output is correct
12 Correct 59 ms 142416 KB Output is correct
13 Correct 58 ms 142508 KB Output is correct
14 Correct 60 ms 142164 KB Output is correct
15 Correct 57 ms 142720 KB Output is correct
16 Correct 62 ms 141996 KB Output is correct
17 Correct 58 ms 142224 KB Output is correct
18 Correct 58 ms 142692 KB Output is correct
19 Correct 55 ms 142156 KB Output is correct
20 Correct 56 ms 142448 KB Output is correct
21 Correct 65 ms 143440 KB Output is correct
22 Correct 73 ms 144464 KB Output is correct
23 Correct 75 ms 145236 KB Output is correct
24 Correct 72 ms 146692 KB Output is correct
25 Correct 64 ms 146260 KB Output is correct
26 Correct 70 ms 146996 KB Output is correct
27 Correct 80 ms 146220 KB Output is correct
28 Correct 73 ms 146648 KB Output is correct
29 Correct 69 ms 147104 KB Output is correct
30 Correct 84 ms 146692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 141648 KB Output is correct
2 Correct 54 ms 141860 KB Output is correct
3 Correct 57 ms 141952 KB Output is correct
4 Correct 56 ms 141648 KB Output is correct
5 Correct 54 ms 141872 KB Output is correct
6 Correct 56 ms 141912 KB Output is correct
7 Correct 54 ms 141904 KB Output is correct
8 Correct 54 ms 141856 KB Output is correct
9 Correct 56 ms 142096 KB Output is correct
10 Correct 54 ms 142188 KB Output is correct
11 Correct 246 ms 170832 KB Output is correct
12 Correct 453 ms 203600 KB Output is correct
13 Correct 388 ms 201556 KB Output is correct
14 Correct 578 ms 197732 KB Output is correct
15 Correct 609 ms 197764 KB Output is correct
16 Correct 573 ms 196248 KB Output is correct
17 Correct 354 ms 200792 KB Output is correct
18 Correct 1043 ms 224080 KB Output is correct
19 Correct 1222 ms 231880 KB Output is correct
20 Correct 408 ms 195156 KB Output is correct
21 Correct 60 ms 142164 KB Output is correct
22 Correct 59 ms 142416 KB Output is correct
23 Correct 58 ms 142508 KB Output is correct
24 Correct 60 ms 142164 KB Output is correct
25 Correct 57 ms 142720 KB Output is correct
26 Correct 62 ms 141996 KB Output is correct
27 Correct 58 ms 142224 KB Output is correct
28 Correct 58 ms 142692 KB Output is correct
29 Correct 55 ms 142156 KB Output is correct
30 Correct 56 ms 142448 KB Output is correct
31 Correct 65 ms 143440 KB Output is correct
32 Correct 73 ms 144464 KB Output is correct
33 Correct 75 ms 145236 KB Output is correct
34 Correct 72 ms 146692 KB Output is correct
35 Correct 64 ms 146260 KB Output is correct
36 Correct 70 ms 146996 KB Output is correct
37 Correct 80 ms 146220 KB Output is correct
38 Correct 73 ms 146648 KB Output is correct
39 Correct 69 ms 147104 KB Output is correct
40 Correct 84 ms 146692 KB Output is correct
41 Correct 163 ms 159312 KB Output is correct
42 Correct 468 ms 200136 KB Output is correct
43 Correct 183 ms 187088 KB Output is correct
44 Correct 310 ms 197204 KB Output is correct
45 Correct 323 ms 199252 KB Output is correct
46 Correct 362 ms 189016 KB Output is correct
47 Correct 500 ms 190032 KB Output is correct
48 Correct 239 ms 196844 KB Output is correct
49 Correct 407 ms 189008 KB Output is correct
50 Correct 417 ms 188464 KB Output is correct
51 Correct 175 ms 183124 KB Output is correct
52 Correct 264 ms 186928 KB Output is correct
53 Correct 243 ms 195924 KB Output is correct
54 Correct 547 ms 209792 KB Output is correct
55 Correct 339 ms 195412 KB Output is correct