Submission #60576

# Submission time Handle Problem Language Result Execution time Memory
60576 2018-07-24T11:09:44 Z aome Parachute rings (IOI12_rings) C++17
100 / 100
1126 ms 77780 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1000005;

int n, m;
int szCircle;
int deg[N];
int sz[N], par[N];
int G[N][3];
bool noSolution;
pair<int, int> E[N];

struct DSU {
	int root;
	int valid;
	int par[N];
	int deg[N];

	int find(int u) { return u == par[u] ? u : par[u] = find(par[u]); }

	void join(int u, int v) { par[find(u)] = find(v); }

	void add(int u, int v) {
		if (!valid || u == root || v == root) return;
		int ru = find(u), rv = find(v);
		if (deg[u] == 2 || deg[v] == 2 || ru == rv) {
			valid = 0; return;
		}
		deg[u]++, deg[v]++;
		join(u, v);
	}

	DSU(int _root) {
		valid = 1, root = _root;
		for (int i = 0; i < n; ++i) par[i] = i, deg[i] = 0;
		for (int i = 0; i < m; ++i) add(E[i].first, E[i].second);
	}
};

vector<DSU> vec;

int find(int u) { return u == par[u] ? u : par[u] = find(par[u]); }

bool join(int u, int v) {
	u = find(u), v = find(v);
	if (u == v) return 0;
	sz[u] += sz[v], par[v] = u; return 1;
}

void Init(int _n) {
	n = _n;
	for (int i = 0; i < n; ++i) sz[i] = 1, par[i] = i;
}

void Link(int A, int B) {
	if (noSolution) return;
	if (vec.size()) {
		for (int i = 0; i < vec.size(); ++i) vec[i].add(A, B);
		return;
	}
	E[m++] = {A, B};
	G[A][deg[A]++] = B;
	G[B][deg[B]++] = A;
	if (deg[A] < deg[B]) swap(A, B);
	if (deg[A] == 3) {
		vec.push_back(DSU(A));
		for (int i = 0; i < 3; ++i) {
			vec.push_back(DSU(G[A][i]));
		}
		return;
	}
	if (!join(A, B)) {
		if (szCircle) {
			noSolution = 1; return;
		}
		szCircle = sz[find(A)];
	}
}

int CountCritical() {
	if (noSolution) return 0;
	int res = 0;
	if (vec.size()) {
		for (int i = 0; i < vec.size(); ++i) res += vec[i].valid;
	}
	else if (szCircle) res = szCircle;
	else res = n;
	return res;
}

Compilation message

rings.cpp: In function 'void Link(int, int)':
rings.cpp:60:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < vec.size(); ++i) vec[i].add(A, B);
                   ~~^~~~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:86:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < vec.size(); ++i) res += vec[i].valid;
                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 48 ms 39908 KB Output is correct
3 Correct 48 ms 39908 KB Output is correct
4 Correct 2 ms 39908 KB Output is correct
5 Correct 3 ms 39908 KB Output is correct
6 Correct 3 ms 39908 KB Output is correct
7 Correct 47 ms 39908 KB Output is correct
8 Correct 3 ms 39908 KB Output is correct
9 Correct 47 ms 39908 KB Output is correct
10 Correct 53 ms 39908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 39908 KB Output is correct
2 Correct 558 ms 66824 KB Output is correct
3 Correct 446 ms 70920 KB Output is correct
4 Correct 803 ms 70920 KB Output is correct
5 Correct 860 ms 70920 KB Output is correct
6 Correct 836 ms 70920 KB Output is correct
7 Correct 408 ms 71100 KB Output is correct
8 Correct 944 ms 74244 KB Output is correct
9 Correct 1126 ms 77780 KB Output is correct
10 Correct 591 ms 77780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 48 ms 39908 KB Output is correct
3 Correct 48 ms 39908 KB Output is correct
4 Correct 2 ms 39908 KB Output is correct
5 Correct 3 ms 39908 KB Output is correct
6 Correct 3 ms 39908 KB Output is correct
7 Correct 47 ms 39908 KB Output is correct
8 Correct 3 ms 39908 KB Output is correct
9 Correct 47 ms 39908 KB Output is correct
10 Correct 53 ms 39908 KB Output is correct
11 Correct 48 ms 77780 KB Output is correct
12 Correct 55 ms 77780 KB Output is correct
13 Correct 48 ms 77780 KB Output is correct
14 Correct 46 ms 77780 KB Output is correct
15 Correct 48 ms 77780 KB Output is correct
16 Correct 5 ms 77780 KB Output is correct
17 Correct 49 ms 77780 KB Output is correct
18 Correct 49 ms 77780 KB Output is correct
19 Correct 5 ms 77780 KB Output is correct
20 Correct 49 ms 77780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 48 ms 39908 KB Output is correct
3 Correct 48 ms 39908 KB Output is correct
4 Correct 2 ms 39908 KB Output is correct
5 Correct 3 ms 39908 KB Output is correct
6 Correct 3 ms 39908 KB Output is correct
7 Correct 47 ms 39908 KB Output is correct
8 Correct 3 ms 39908 KB Output is correct
9 Correct 47 ms 39908 KB Output is correct
10 Correct 53 ms 39908 KB Output is correct
11 Correct 48 ms 77780 KB Output is correct
12 Correct 55 ms 77780 KB Output is correct
13 Correct 48 ms 77780 KB Output is correct
14 Correct 46 ms 77780 KB Output is correct
15 Correct 48 ms 77780 KB Output is correct
16 Correct 5 ms 77780 KB Output is correct
17 Correct 49 ms 77780 KB Output is correct
18 Correct 49 ms 77780 KB Output is correct
19 Correct 5 ms 77780 KB Output is correct
20 Correct 49 ms 77780 KB Output is correct
21 Correct 18 ms 77780 KB Output is correct
22 Correct 32 ms 77780 KB Output is correct
23 Correct 38 ms 77780 KB Output is correct
24 Correct 79 ms 77780 KB Output is correct
25 Correct 61 ms 77780 KB Output is correct
26 Correct 77 ms 77780 KB Output is correct
27 Correct 39 ms 77780 KB Output is correct
28 Correct 79 ms 77780 KB Output is correct
29 Correct 74 ms 77780 KB Output is correct
30 Correct 44 ms 77780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 48 ms 39908 KB Output is correct
3 Correct 48 ms 39908 KB Output is correct
4 Correct 2 ms 39908 KB Output is correct
5 Correct 3 ms 39908 KB Output is correct
6 Correct 3 ms 39908 KB Output is correct
7 Correct 47 ms 39908 KB Output is correct
8 Correct 3 ms 39908 KB Output is correct
9 Correct 47 ms 39908 KB Output is correct
10 Correct 53 ms 39908 KB Output is correct
11 Correct 318 ms 39908 KB Output is correct
12 Correct 558 ms 66824 KB Output is correct
13 Correct 446 ms 70920 KB Output is correct
14 Correct 803 ms 70920 KB Output is correct
15 Correct 860 ms 70920 KB Output is correct
16 Correct 836 ms 70920 KB Output is correct
17 Correct 408 ms 71100 KB Output is correct
18 Correct 944 ms 74244 KB Output is correct
19 Correct 1126 ms 77780 KB Output is correct
20 Correct 591 ms 77780 KB Output is correct
21 Correct 48 ms 77780 KB Output is correct
22 Correct 55 ms 77780 KB Output is correct
23 Correct 48 ms 77780 KB Output is correct
24 Correct 46 ms 77780 KB Output is correct
25 Correct 48 ms 77780 KB Output is correct
26 Correct 5 ms 77780 KB Output is correct
27 Correct 49 ms 77780 KB Output is correct
28 Correct 49 ms 77780 KB Output is correct
29 Correct 5 ms 77780 KB Output is correct
30 Correct 49 ms 77780 KB Output is correct
31 Correct 18 ms 77780 KB Output is correct
32 Correct 32 ms 77780 KB Output is correct
33 Correct 38 ms 77780 KB Output is correct
34 Correct 79 ms 77780 KB Output is correct
35 Correct 61 ms 77780 KB Output is correct
36 Correct 77 ms 77780 KB Output is correct
37 Correct 39 ms 77780 KB Output is correct
38 Correct 79 ms 77780 KB Output is correct
39 Correct 74 ms 77780 KB Output is correct
40 Correct 44 ms 77780 KB Output is correct
41 Correct 221 ms 77780 KB Output is correct
42 Correct 572 ms 77780 KB Output is correct
43 Correct 286 ms 77780 KB Output is correct
44 Correct 371 ms 77780 KB Output is correct
45 Correct 492 ms 77780 KB Output is correct
46 Correct 607 ms 77780 KB Output is correct
47 Correct 718 ms 77780 KB Output is correct
48 Correct 348 ms 77780 KB Output is correct
49 Correct 629 ms 77780 KB Output is correct
50 Correct 629 ms 77780 KB Output is correct
51 Correct 279 ms 77780 KB Output is correct
52 Correct 344 ms 77780 KB Output is correct
53 Correct 302 ms 77780 KB Output is correct
54 Correct 869 ms 77780 KB Output is correct
55 Correct 512 ms 77780 KB Output is correct