Submission #727642

# Submission time Handle Problem Language Result Execution time Memory
727642 2023-04-21T04:43:12 Z SanguineChameleon Duathlon (APIO18_duathlon) C++17
47 / 100
80 ms 21232 KB
#include <bits/stdc++.h>
using namespace std;

void just_do_it();

int main() {
	#ifdef KAMIRULEZ
		freopen("kamirulez.inp", "r", stdin);
		freopen("kamirulez.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	just_do_it();
	return 0;
}

const int maxn = 1e5 + 20;
vector<int> adj[maxn];
vector<int> adj_tree[maxn];
vector<int> comp;
bool can[55][55][55];
bool bad[maxn];
bool flag[maxn];
int sz[maxn];
int node_cnt = 0;
int edge_cnt = 0;
int n, m;

void dfs(int x, int a, int b) {
	can[x][a][b] = true;
	for (auto c: adj[b]) {
		if (c != x && !can[x][a][c]) {
			dfs(x, a, c);
		}
	}
}

void dfs1(int u) {
	comp.push_back(u);
	flag[u] = true;
	node_cnt++;
	edge_cnt += adj[u].size();
	sz[u] = 1;
	for (auto v: adj[u]) {
		if (!flag[v]) {
			adj_tree[u].push_back(v);
			adj_tree[v].push_back(u);
			dfs1(v);
			sz[u] += sz[v];
		}
	}
}

void sub1() {
	for (int x = 1; x <= n; x++) {
		for (int a = 1; a <= n; a++) {
			if (a != x) {
				dfs(x, a, a);
			}
		}
		bad[x] = false;
	}
	int res = 0;
	for (int a = 1; a <= n; a++) {
		for (int b = 1; b <= n; b++) {
			if (b == a) {
				continue;
			}
			for (int c = 1; c <= n; c++) {
				if (c == a || c == b) {
					continue;
				}
				bool ok = true;
				for (int x = 1; x <= n; x++) {
					if (x == b) {
						continue;
					}
					if (!can[x][a][b] && !can[x][b][c]) {
						ok = false;
						break;
					}
				}
				if (ok) {
					res++;
				}
			}
		}
	}
	cout << res;
}

long long solve(int root) {
	comp.clear();
	node_cnt = 0;
	edge_cnt = 0;
	dfs1(root);
	edge_cnt /= 2;
	if (node_cnt == edge_cnt) {
		return 1LL * node_cnt * (node_cnt - 1) * (node_cnt - 2);
	}
	long long res = 0;
	for (auto u: comp) {
		res += 1LL * sz[u] * (node_cnt - sz[u]) * 2;
	}
	res -= 1LL * node_cnt * (node_cnt - 1);
	return res;
}

void sub8() {


}

void just_do_it() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	if (n <= 50) {
		sub1();
		return;
	}
	if (n <= 2000 && false) {
		sub8();
		return;
	}
	long long res = 0;
	for (int i = 1; i <= n; i++) {
		if (!flag[i]) {
			res += solve(i);
		}
	}
	cout << res;
	return;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 3 ms 5020 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 4 ms 5036 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5024 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 5024 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 5024 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 3 ms 5020 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 4 ms 5036 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5024 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 5024 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 5024 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5060 KB Output is correct
38 Correct 8 ms 5148 KB Output is correct
39 Correct 10 ms 5076 KB Output is correct
40 Correct 11 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 4 ms 5076 KB Output is correct
44 Correct 4 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 4 ms 5148 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5176 KB Output is correct
51 Correct 8 ms 5156 KB Output is correct
52 Correct 8 ms 5076 KB Output is correct
53 Correct 9 ms 5076 KB Output is correct
54 Correct 10 ms 5076 KB Output is correct
55 Correct 9 ms 5076 KB Output is correct
56 Correct 9 ms 5076 KB Output is correct
57 Correct 8 ms 5152 KB Output is correct
58 Correct 11 ms 5156 KB Output is correct
59 Correct 7 ms 5076 KB Output is correct
60 Correct 7 ms 5152 KB Output is correct
61 Correct 5 ms 5076 KB Output is correct
62 Correct 4 ms 5076 KB Output is correct
63 Correct 8 ms 5148 KB Output is correct
64 Correct 7 ms 5184 KB Output is correct
65 Correct 7 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 21232 KB Output is correct
2 Correct 76 ms 21188 KB Output is correct
3 Correct 68 ms 17096 KB Output is correct
4 Correct 66 ms 19088 KB Output is correct
5 Correct 70 ms 15708 KB Output is correct
6 Correct 73 ms 15816 KB Output is correct
7 Correct 65 ms 14644 KB Output is correct
8 Correct 66 ms 15284 KB Output is correct
9 Correct 66 ms 13916 KB Output is correct
10 Correct 64 ms 14460 KB Output is correct
11 Correct 53 ms 12656 KB Output is correct
12 Correct 59 ms 12576 KB Output is correct
13 Correct 51 ms 12308 KB Output is correct
14 Correct 53 ms 12072 KB Output is correct
15 Correct 42 ms 11184 KB Output is correct
16 Correct 42 ms 11096 KB Output is correct
17 Correct 4 ms 5536 KB Output is correct
18 Correct 4 ms 5500 KB Output is correct
19 Correct 4 ms 5460 KB Output is correct
20 Correct 4 ms 5404 KB Output is correct
21 Correct 4 ms 5404 KB Output is correct
22 Correct 4 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 5036 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5032 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5032 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5032 KB Output is correct
18 Correct 3 ms 5032 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13596 KB Output is correct
2 Correct 69 ms 13612 KB Output is correct
3 Correct 63 ms 13576 KB Output is correct
4 Correct 60 ms 13600 KB Output is correct
5 Correct 64 ms 13548 KB Output is correct
6 Correct 73 ms 17600 KB Output is correct
7 Correct 65 ms 16244 KB Output is correct
8 Correct 78 ms 15436 KB Output is correct
9 Correct 67 ms 14736 KB Output is correct
10 Correct 62 ms 13384 KB Output is correct
11 Correct 58 ms 13508 KB Output is correct
12 Correct 58 ms 13240 KB Output is correct
13 Correct 57 ms 13304 KB Output is correct
14 Correct 52 ms 12832 KB Output is correct
15 Correct 55 ms 12496 KB Output is correct
16 Correct 33 ms 10700 KB Output is correct
17 Correct 44 ms 14188 KB Output is correct
18 Correct 41 ms 14144 KB Output is correct
19 Correct 47 ms 14232 KB Output is correct
20 Correct 55 ms 14224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Incorrect 3 ms 5076 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 71 ms 13620 KB Output is correct
2 Correct 64 ms 13508 KB Output is correct
3 Incorrect 80 ms 13632 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 3 ms 5020 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 4 ms 5036 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5024 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 5024 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 5024 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5060 KB Output is correct
38 Correct 8 ms 5148 KB Output is correct
39 Correct 10 ms 5076 KB Output is correct
40 Correct 11 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 4 ms 5076 KB Output is correct
44 Correct 4 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 4 ms 5148 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5176 KB Output is correct
51 Correct 8 ms 5156 KB Output is correct
52 Correct 8 ms 5076 KB Output is correct
53 Correct 9 ms 5076 KB Output is correct
54 Correct 10 ms 5076 KB Output is correct
55 Correct 9 ms 5076 KB Output is correct
56 Correct 9 ms 5076 KB Output is correct
57 Correct 8 ms 5152 KB Output is correct
58 Correct 11 ms 5156 KB Output is correct
59 Correct 7 ms 5076 KB Output is correct
60 Correct 7 ms 5152 KB Output is correct
61 Correct 5 ms 5076 KB Output is correct
62 Correct 4 ms 5076 KB Output is correct
63 Correct 8 ms 5148 KB Output is correct
64 Correct 7 ms 5184 KB Output is correct
65 Correct 7 ms 5076 KB Output is correct
66 Correct 3 ms 4948 KB Output is correct
67 Correct 3 ms 5076 KB Output is correct
68 Incorrect 3 ms 5032 KB Output isn't correct
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 3 ms 5020 KB Output is correct
7 Correct 3 ms 5024 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 4 ms 5036 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5024 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 5024 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 5024 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5060 KB Output is correct
38 Correct 8 ms 5148 KB Output is correct
39 Correct 10 ms 5076 KB Output is correct
40 Correct 11 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 4 ms 5076 KB Output is correct
44 Correct 4 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 4 ms 5148 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5176 KB Output is correct
51 Correct 8 ms 5156 KB Output is correct
52 Correct 8 ms 5076 KB Output is correct
53 Correct 9 ms 5076 KB Output is correct
54 Correct 10 ms 5076 KB Output is correct
55 Correct 9 ms 5076 KB Output is correct
56 Correct 9 ms 5076 KB Output is correct
57 Correct 8 ms 5152 KB Output is correct
58 Correct 11 ms 5156 KB Output is correct
59 Correct 7 ms 5076 KB Output is correct
60 Correct 7 ms 5152 KB Output is correct
61 Correct 5 ms 5076 KB Output is correct
62 Correct 4 ms 5076 KB Output is correct
63 Correct 8 ms 5148 KB Output is correct
64 Correct 7 ms 5184 KB Output is correct
65 Correct 7 ms 5076 KB Output is correct
66 Correct 77 ms 21232 KB Output is correct
67 Correct 76 ms 21188 KB Output is correct
68 Correct 68 ms 17096 KB Output is correct
69 Correct 66 ms 19088 KB Output is correct
70 Correct 70 ms 15708 KB Output is correct
71 Correct 73 ms 15816 KB Output is correct
72 Correct 65 ms 14644 KB Output is correct
73 Correct 66 ms 15284 KB Output is correct
74 Correct 66 ms 13916 KB Output is correct
75 Correct 64 ms 14460 KB Output is correct
76 Correct 53 ms 12656 KB Output is correct
77 Correct 59 ms 12576 KB Output is correct
78 Correct 51 ms 12308 KB Output is correct
79 Correct 53 ms 12072 KB Output is correct
80 Correct 42 ms 11184 KB Output is correct
81 Correct 42 ms 11096 KB Output is correct
82 Correct 4 ms 5536 KB Output is correct
83 Correct 4 ms 5500 KB Output is correct
84 Correct 4 ms 5460 KB Output is correct
85 Correct 4 ms 5404 KB Output is correct
86 Correct 4 ms 5404 KB Output is correct
87 Correct 4 ms 5460 KB Output is correct
88 Correct 3 ms 5076 KB Output is correct
89 Correct 3 ms 5028 KB Output is correct
90 Correct 3 ms 5036 KB Output is correct
91 Correct 3 ms 5076 KB Output is correct
92 Correct 3 ms 5076 KB Output is correct
93 Correct 4 ms 5076 KB Output is correct
94 Correct 4 ms 5076 KB Output is correct
95 Correct 3 ms 5076 KB Output is correct
96 Correct 3 ms 5076 KB Output is correct
97 Correct 3 ms 5076 KB Output is correct
98 Correct 3 ms 5076 KB Output is correct
99 Correct 3 ms 5032 KB Output is correct
100 Correct 4 ms 5076 KB Output is correct
101 Correct 3 ms 5076 KB Output is correct
102 Correct 4 ms 5032 KB Output is correct
103 Correct 3 ms 5076 KB Output is correct
104 Correct 3 ms 5032 KB Output is correct
105 Correct 3 ms 5032 KB Output is correct
106 Correct 3 ms 5076 KB Output is correct
107 Correct 3 ms 5028 KB Output is correct
108 Correct 59 ms 13596 KB Output is correct
109 Correct 69 ms 13612 KB Output is correct
110 Correct 63 ms 13576 KB Output is correct
111 Correct 60 ms 13600 KB Output is correct
112 Correct 64 ms 13548 KB Output is correct
113 Correct 73 ms 17600 KB Output is correct
114 Correct 65 ms 16244 KB Output is correct
115 Correct 78 ms 15436 KB Output is correct
116 Correct 67 ms 14736 KB Output is correct
117 Correct 62 ms 13384 KB Output is correct
118 Correct 58 ms 13508 KB Output is correct
119 Correct 58 ms 13240 KB Output is correct
120 Correct 57 ms 13304 KB Output is correct
121 Correct 52 ms 12832 KB Output is correct
122 Correct 55 ms 12496 KB Output is correct
123 Correct 33 ms 10700 KB Output is correct
124 Correct 44 ms 14188 KB Output is correct
125 Correct 41 ms 14144 KB Output is correct
126 Correct 47 ms 14232 KB Output is correct
127 Correct 55 ms 14224 KB Output is correct
128 Correct 3 ms 5076 KB Output is correct
129 Correct 3 ms 5076 KB Output is correct
130 Incorrect 3 ms 5076 KB Output isn't correct
131 Halted 0 ms 0 KB -