Submission #760664

# Submission time Handle Problem Language Result Execution time Memory
760664 2023-06-18T05:41:06 Z ymm Parachute rings (IOI12_rings) C++17
100 / 100
1110 ms 130160 KB
#include <bits/stdc++.h>
#define Loop(x,l,r)  for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int,int> pii;
using namespace std;

const int N = 1<<20;
vector<int> A[N];
int n;

struct graph {
	int deg[N];
	int rem;
	int par[N];
	bool has3;
	int sz[N];
	int szc;

	void init() {
		fill(par, par+N, -1);
		fill(sz, sz+N, 1);
		szc = -1;
		rem = -1;
	}
	int rt(int v) { return par[v] == -1? v: (par[v] = rt(par[v])); }
	void unite(int v, int u) {
		if (v == rem || u == rem)
			return;
		deg[v]++;
		deg[u]++;
		if (deg[v] >= 3 || deg[u] >= 3)
			has3 = 1;
		v = rt(v);
		u = rt(u);
		if (v == u) {
			szc = szc == -1? sz[v]: -2;
			return;
		}
		if (sz[v] < sz[u])
			swap(v, u);
		par[u] = v;
		sz[v] += sz[u];
	}
};

void make_by_rem(graph &G, int rem) {
	G.init();
	G.rem = rem;
	Loop (v,0,n) {
		for (int u : A[v]) {
			if (v > u)
				continue;
			G.unite(v, u);
		}
	}
}

graph G, G3[4];

int v3 = -1;

void Init(int N_) {
	n = N_;
	G.init();
}

void Link(int v, int u) {
	A[v].push_back(u);
	A[u].push_back(v);

	if (v3 != -1) {
		for (auto &G : G3)
			G.unite(v, u);
	} else {
		G.unite(v, u);
	}

	for (int x : {v, u}) {
		if (v3 == -1 && A[x].size() == 3) {
			v3 = x;
			make_by_rem(G3[0], x);
			Loop (i,0,3)
				make_by_rem(G3[i+1], A[x][i]);
		}
	}
}

int CountCritical() {
	if (v3 != -1) {
		int ans = 0;
		for (auto &G : G3)
			ans += G.szc == -1 && !G.has3;
		return ans;
	} else {
		switch (G.szc) {
		case -2: return 0;
		case -1: return n;
		default: return G.szc;
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 33108 KB Output is correct
2 Correct 39 ms 66260 KB Output is correct
3 Correct 30 ms 66216 KB Output is correct
4 Correct 17 ms 33196 KB Output is correct
5 Correct 17 ms 33236 KB Output is correct
6 Correct 19 ms 33296 KB Output is correct
7 Correct 37 ms 66064 KB Output is correct
8 Correct 18 ms 33284 KB Output is correct
9 Correct 34 ms 66296 KB Output is correct
10 Correct 36 ms 66224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 297 ms 51884 KB Output is correct
2 Correct 862 ms 106864 KB Output is correct
3 Correct 1052 ms 113060 KB Output is correct
4 Correct 878 ms 68488 KB Output is correct
5 Correct 847 ms 81704 KB Output is correct
6 Correct 806 ms 80212 KB Output is correct
7 Correct 1036 ms 124428 KB Output is correct
8 Correct 1110 ms 126100 KB Output is correct
9 Correct 1109 ms 130160 KB Output is correct
10 Correct 457 ms 79200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 33108 KB Output is correct
2 Correct 39 ms 66260 KB Output is correct
3 Correct 30 ms 66216 KB Output is correct
4 Correct 17 ms 33196 KB Output is correct
5 Correct 17 ms 33236 KB Output is correct
6 Correct 19 ms 33296 KB Output is correct
7 Correct 37 ms 66064 KB Output is correct
8 Correct 18 ms 33284 KB Output is correct
9 Correct 34 ms 66296 KB Output is correct
10 Correct 36 ms 66224 KB Output is correct
11 Correct 27 ms 66316 KB Output is correct
12 Correct 32 ms 66636 KB Output is correct
13 Correct 45 ms 66616 KB Output is correct
14 Correct 49 ms 66432 KB Output is correct
15 Correct 31 ms 66468 KB Output is correct
16 Correct 19 ms 33604 KB Output is correct
17 Correct 42 ms 66628 KB Output is correct
18 Correct 32 ms 66804 KB Output is correct
19 Correct 20 ms 33608 KB Output is correct
20 Correct 32 ms 66644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 33108 KB Output is correct
2 Correct 39 ms 66260 KB Output is correct
3 Correct 30 ms 66216 KB Output is correct
4 Correct 17 ms 33196 KB Output is correct
5 Correct 17 ms 33236 KB Output is correct
6 Correct 19 ms 33296 KB Output is correct
7 Correct 37 ms 66064 KB Output is correct
8 Correct 18 ms 33284 KB Output is correct
9 Correct 34 ms 66296 KB Output is correct
10 Correct 36 ms 66224 KB Output is correct
11 Correct 27 ms 66316 KB Output is correct
12 Correct 32 ms 66636 KB Output is correct
13 Correct 45 ms 66616 KB Output is correct
14 Correct 49 ms 66432 KB Output is correct
15 Correct 31 ms 66468 KB Output is correct
16 Correct 19 ms 33604 KB Output is correct
17 Correct 42 ms 66628 KB Output is correct
18 Correct 32 ms 66804 KB Output is correct
19 Correct 20 ms 33608 KB Output is correct
20 Correct 32 ms 66644 KB Output is correct
21 Correct 30 ms 34700 KB Output is correct
22 Correct 49 ms 35664 KB Output is correct
23 Correct 46 ms 36308 KB Output is correct
24 Correct 68 ms 69808 KB Output is correct
25 Correct 37 ms 68172 KB Output is correct
26 Correct 63 ms 70776 KB Output is correct
27 Correct 45 ms 37208 KB Output is correct
28 Correct 68 ms 71476 KB Output is correct
29 Correct 50 ms 70092 KB Output is correct
30 Correct 46 ms 37784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 33108 KB Output is correct
2 Correct 39 ms 66260 KB Output is correct
3 Correct 30 ms 66216 KB Output is correct
4 Correct 17 ms 33196 KB Output is correct
5 Correct 17 ms 33236 KB Output is correct
6 Correct 19 ms 33296 KB Output is correct
7 Correct 37 ms 66064 KB Output is correct
8 Correct 18 ms 33284 KB Output is correct
9 Correct 34 ms 66296 KB Output is correct
10 Correct 36 ms 66224 KB Output is correct
11 Correct 297 ms 51884 KB Output is correct
12 Correct 862 ms 106864 KB Output is correct
13 Correct 1052 ms 113060 KB Output is correct
14 Correct 878 ms 68488 KB Output is correct
15 Correct 847 ms 81704 KB Output is correct
16 Correct 806 ms 80212 KB Output is correct
17 Correct 1036 ms 124428 KB Output is correct
18 Correct 1110 ms 126100 KB Output is correct
19 Correct 1109 ms 130160 KB Output is correct
20 Correct 457 ms 79200 KB Output is correct
21 Correct 27 ms 66316 KB Output is correct
22 Correct 32 ms 66636 KB Output is correct
23 Correct 45 ms 66616 KB Output is correct
24 Correct 49 ms 66432 KB Output is correct
25 Correct 31 ms 66468 KB Output is correct
26 Correct 19 ms 33604 KB Output is correct
27 Correct 42 ms 66628 KB Output is correct
28 Correct 32 ms 66804 KB Output is correct
29 Correct 20 ms 33608 KB Output is correct
30 Correct 32 ms 66644 KB Output is correct
31 Correct 30 ms 34700 KB Output is correct
32 Correct 49 ms 35664 KB Output is correct
33 Correct 46 ms 36308 KB Output is correct
34 Correct 68 ms 69808 KB Output is correct
35 Correct 37 ms 68172 KB Output is correct
36 Correct 63 ms 70776 KB Output is correct
37 Correct 45 ms 37208 KB Output is correct
38 Correct 68 ms 71476 KB Output is correct
39 Correct 50 ms 70092 KB Output is correct
40 Correct 46 ms 37784 KB Output is correct
41 Correct 161 ms 47160 KB Output is correct
42 Correct 482 ms 105304 KB Output is correct
43 Correct 260 ms 87924 KB Output is correct
44 Correct 702 ms 124168 KB Output is correct
45 Correct 751 ms 115520 KB Output is correct
46 Correct 574 ms 74472 KB Output is correct
47 Correct 686 ms 75156 KB Output is correct
48 Correct 513 ms 108448 KB Output is correct
49 Correct 439 ms 73072 KB Output is correct
50 Correct 516 ms 72672 KB Output is correct
51 Correct 299 ms 89980 KB Output is correct
52 Correct 633 ms 113544 KB Output is correct
53 Correct 520 ms 108884 KB Output is correct
54 Correct 998 ms 118780 KB Output is correct
55 Correct 974 ms 123108 KB Output is correct