Submission #760826

# Submission time Handle Problem Language Result Execution time Memory
760826 2023-06-18T15:42:17 Z Sohsoh84 Parachute rings (IOI12_rings) C++17
100 / 100
1508 ms 114196 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pll;

#define X		first
#define Y		second
#define debug(x)	cerr << #x << ": " << x << endl;

const ll MAXN = 1e6 + 10;
const ll MAXC = 5;

int n, mx[MAXC], par[MAXC][MAXN], ig[MAXN], deg[MAXC][MAXN], sz[MAXC][MAXN], 
    cyc_cnt[MAXC], cyc_sz[MAXC], cmp = 1;
bool deg_ex;
vector<int> poss, adj[MAXN];
vector<pll> edges;

int find(int ind, int v) {
	return par[ind][v] == v ? v : par[ind][v] = find(ind, par[ind][v]);
}

inline void unite(int ind, int u, int v) {
	if (u == ig[ind] || v == ig[ind]) return;

	deg[ind][u]++;
	deg[ind][v]++;
	mx[ind] = max(mx[ind], deg[ind][u]);
	mx[ind] = max(mx[ind], deg[ind][v]);

	u = find(ind, u), v = find(ind, v);
	if (u == v) {
		cyc_cnt[ind]++;
		cyc_sz[ind] += sz[ind][u];
		return;
	}

	par[ind][v] = u;
	sz[ind][u] += sz[ind][v];
}

inline void init(int ind, int v = 0) {
	ig[ind] = v;
	for (int i = 1; i <= n; i++) {
		par[ind][i] = i;
		sz[ind][i] = 1;
		deg[ind][i] = 0;
	}

	mx[ind] = 0;
	cyc_cnt[ind] = 0;
	cyc_sz[ind] = 0;
	for (auto [u, v] : edges)
		unite(ind, u, v);
}

void Init(int N_) {
	n = N_;
	deg_ex = false;
	init(0);
}

inline void check(int v) {
	if (deg_ex) return;
	if (int(adj[v].size()) > 2) {
		deg_ex = true;
		poss.push_back(v);
		for (int u : adj[v]) poss.push_back(u);

		cmp = poss.size();
		for (int i = 0; i < cmp; i++)
			init(i, poss[i]);
	}
}

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

	check(u);
	check(v);

	for (int i = 0; i < cmp; i++)
		unite(i, u, v);

	edges.push_back({u, v});
}

int CountCritical() {
	if (!deg_ex) {
		if (cyc_cnt[0] == 0) return n;
		else if (cyc_cnt[0] == 1) return cyc_sz[0];
		return 0;
	}

	int ans = 0;
	for (int i = 0; i < cmp; i++)
		if (mx[i] <= 2 && cyc_cnt[i] == 0)
			ans++;

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 24276 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23892 KB Output is correct
6 Correct 13 ms 24124 KB Output is correct
7 Correct 12 ms 24136 KB Output is correct
8 Correct 13 ms 24092 KB Output is correct
9 Correct 14 ms 24364 KB Output is correct
10 Correct 13 ms 24352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 243 ms 50196 KB Output is correct
2 Correct 941 ms 92724 KB Output is correct
3 Correct 1508 ms 105368 KB Output is correct
4 Correct 790 ms 74636 KB Output is correct
5 Correct 807 ms 74652 KB Output is correct
6 Correct 784 ms 73536 KB Output is correct
7 Correct 1424 ms 104504 KB Output is correct
8 Correct 1033 ms 104448 KB Output is correct
9 Correct 1047 ms 109812 KB Output is correct
10 Correct 511 ms 73004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 24276 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23892 KB Output is correct
6 Correct 13 ms 24124 KB Output is correct
7 Correct 12 ms 24136 KB Output is correct
8 Correct 13 ms 24092 KB Output is correct
9 Correct 14 ms 24364 KB Output is correct
10 Correct 13 ms 24352 KB Output is correct
11 Correct 14 ms 24404 KB Output is correct
12 Correct 16 ms 24892 KB Output is correct
13 Correct 19 ms 24904 KB Output is correct
14 Correct 15 ms 24660 KB Output is correct
15 Correct 15 ms 25140 KB Output is correct
16 Correct 14 ms 24404 KB Output is correct
17 Correct 16 ms 24916 KB Output is correct
18 Correct 16 ms 25432 KB Output is correct
19 Correct 15 ms 24512 KB Output is correct
20 Correct 16 ms 24908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 24276 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23892 KB Output is correct
6 Correct 13 ms 24124 KB Output is correct
7 Correct 12 ms 24136 KB Output is correct
8 Correct 13 ms 24092 KB Output is correct
9 Correct 14 ms 24364 KB Output is correct
10 Correct 13 ms 24352 KB Output is correct
11 Correct 14 ms 24404 KB Output is correct
12 Correct 16 ms 24892 KB Output is correct
13 Correct 19 ms 24904 KB Output is correct
14 Correct 15 ms 24660 KB Output is correct
15 Correct 15 ms 25140 KB Output is correct
16 Correct 14 ms 24404 KB Output is correct
17 Correct 16 ms 24916 KB Output is correct
18 Correct 16 ms 25432 KB Output is correct
19 Correct 15 ms 24512 KB Output is correct
20 Correct 16 ms 24908 KB Output is correct
21 Correct 25 ms 25952 KB Output is correct
22 Correct 33 ms 27232 KB Output is correct
23 Correct 38 ms 28124 KB Output is correct
24 Correct 49 ms 30968 KB Output is correct
25 Correct 26 ms 29288 KB Output is correct
26 Correct 46 ms 31764 KB Output is correct
27 Correct 46 ms 29124 KB Output is correct
28 Correct 50 ms 32496 KB Output is correct
29 Correct 46 ms 30928 KB Output is correct
30 Correct 47 ms 29928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 24276 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23892 KB Output is correct
6 Correct 13 ms 24124 KB Output is correct
7 Correct 12 ms 24136 KB Output is correct
8 Correct 13 ms 24092 KB Output is correct
9 Correct 14 ms 24364 KB Output is correct
10 Correct 13 ms 24352 KB Output is correct
11 Correct 243 ms 50196 KB Output is correct
12 Correct 941 ms 92724 KB Output is correct
13 Correct 1508 ms 105368 KB Output is correct
14 Correct 790 ms 74636 KB Output is correct
15 Correct 807 ms 74652 KB Output is correct
16 Correct 784 ms 73536 KB Output is correct
17 Correct 1424 ms 104504 KB Output is correct
18 Correct 1033 ms 104448 KB Output is correct
19 Correct 1047 ms 109812 KB Output is correct
20 Correct 511 ms 73004 KB Output is correct
21 Correct 14 ms 24404 KB Output is correct
22 Correct 16 ms 24892 KB Output is correct
23 Correct 19 ms 24904 KB Output is correct
24 Correct 15 ms 24660 KB Output is correct
25 Correct 15 ms 25140 KB Output is correct
26 Correct 14 ms 24404 KB Output is correct
27 Correct 16 ms 24916 KB Output is correct
28 Correct 16 ms 25432 KB Output is correct
29 Correct 15 ms 24512 KB Output is correct
30 Correct 16 ms 24908 KB Output is correct
31 Correct 25 ms 25952 KB Output is correct
32 Correct 33 ms 27232 KB Output is correct
33 Correct 38 ms 28124 KB Output is correct
34 Correct 49 ms 30968 KB Output is correct
35 Correct 26 ms 29288 KB Output is correct
36 Correct 46 ms 31764 KB Output is correct
37 Correct 46 ms 29124 KB Output is correct
38 Correct 50 ms 32496 KB Output is correct
39 Correct 46 ms 30928 KB Output is correct
40 Correct 47 ms 29928 KB Output is correct
41 Correct 160 ms 43308 KB Output is correct
42 Correct 392 ms 89396 KB Output is correct
43 Correct 239 ms 74768 KB Output is correct
44 Correct 833 ms 114196 KB Output is correct
45 Correct 1000 ms 106020 KB Output is correct
46 Correct 479 ms 77860 KB Output is correct
47 Correct 705 ms 78876 KB Output is correct
48 Correct 522 ms 96300 KB Output is correct
49 Correct 493 ms 76948 KB Output is correct
50 Correct 542 ms 76452 KB Output is correct
51 Correct 289 ms 71100 KB Output is correct
52 Correct 718 ms 97168 KB Output is correct
53 Correct 525 ms 96688 KB Output is correct
54 Correct 943 ms 104864 KB Output is correct
55 Correct 1182 ms 111836 KB Output is correct