Submission #983225

# Submission time Handle Problem Language Result Execution time Memory
983225 2024-05-15T09:36:41 Z vjudge1 Duathlon (APIO18_duathlon) C++17
36 / 100
50 ms 21084 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m, i, j, k, mask, x, y, ans, sz[200001], rt[200001], dp[11][12345];
bool u[200001], cyc, cyc2[200001];
vector<int> g[200001];
vector<pair<int, int>> v;
set<pair<int, pair<int, int>>> st;

void dfs(int x, int pr, int r) {
	sz[x] = 1;
	u[x] = 1;
	rt[x] = r;
	for (auto y : g[x]) {
		if (y == pr) continue;
		if (u[y]) {
			cyc = 1;
			continue;
		}
		dfs(y, x, r);
		sz[x] += sz[y];
	}
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	#endif
	cin >> n >> m;
	while (m--) {
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	if (n <= 10 && m <= 100) {
		for (int x = 1; x <= n; x++) {
			for (i = 1; i <= n; i++) {
				for (mask = 0; mask < (1ll << n); mask++) dp[i][mask] = 1e18;
				dp[i][0] = 0;
			}
			dp[x][1ll << (x - 1)] = 0;
			for (mask = 0; mask < (1ll << n); mask++) {
				for (i = 1; i <= n; i++) {
					if ((mask >> (i - 1)) & 1ll) continue;
					for (auto j : g[i]) {
						if ((mask >> (j - 1)) & 1ll) {
							dp[i][mask | (1ll << (i - 1))] = min(dp[i][mask | (1ll << (i - 1))], dp[j][mask] + 1);
						}
					}
				}
			}
			for (int y = 1; y <= n; y++) {
				for (mask = 0; mask < (1ll << n); mask++) {
					if (dp[y][mask] < 1e18) {
						for (int z = 1; z <= n; z++) {
							if (!((mask >> (z - 1)) & 1ll)) continue;
							if (x == y || x == z || y == z) continue;
							//cout << x << " " << z << " " << y << " " << mask << "\n";
							st.insert({x, {z, y}});
							st.insert({y, {z, x}});
						}
					}
				}
			}
		}
		cout << st.size();
		return 0;
	}
	for (i = 1; i <= n; i++) {
		if (!u[i]) {
			cyc = 0;
			dfs(i, i, i);
			v.push_back({i, cyc});
		}
	}
	for (auto i : v) {
		if (!i.second) ans -= (sz[i.first]) * (sz[i.first] - 1);
		else {
			cyc2[i.first] = 1;
			ans += (sz[i.first]) * (sz[i.first] - 1) * (sz[i.first] - 2);
		}
	}
	for (i = 1; i <= n; i++) {
		if (!cyc2[rt[i]]) {
			ans += 2 * (sz[i] - 1) * (sz[rt[i]] - sz[i]);
			ans += 2 * (sz[rt[i]] - sz[i]);
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6796 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 5 ms 6748 KB Output is correct
9 Correct 8 ms 6748 KB Output is correct
10 Correct 14 ms 6840 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 3 ms 6788 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 3 ms 6744 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 3 ms 6748 KB Output is correct
20 Correct 2 ms 6788 KB Output is correct
21 Correct 3 ms 6748 KB Output is correct
22 Correct 2 ms 6788 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6744 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 3 ms 6748 KB Output is correct
27 Correct 2 ms 6796 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6788 KB Output is correct
32 Correct 3 ms 7000 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6796 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 5 ms 6748 KB Output is correct
9 Correct 8 ms 6748 KB Output is correct
10 Correct 14 ms 6840 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 3 ms 6788 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 3 ms 6744 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 3 ms 6748 KB Output is correct
20 Correct 2 ms 6788 KB Output is correct
21 Correct 3 ms 6748 KB Output is correct
22 Correct 2 ms 6788 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6744 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 3 ms 6748 KB Output is correct
27 Correct 2 ms 6796 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6788 KB Output is correct
32 Correct 3 ms 7000 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Incorrect 2 ms 8796 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 21072 KB Output is correct
2 Correct 50 ms 21084 KB Output is correct
3 Correct 49 ms 16980 KB Output is correct
4 Correct 34 ms 18956 KB Output is correct
5 Correct 30 ms 15896 KB Output is correct
6 Correct 44 ms 15708 KB Output is correct
7 Correct 30 ms 14676 KB Output is correct
8 Correct 46 ms 15312 KB Output is correct
9 Correct 29 ms 13912 KB Output is correct
10 Correct 46 ms 14672 KB Output is correct
11 Correct 25 ms 13528 KB Output is correct
12 Correct 24 ms 13584 KB Output is correct
13 Correct 22 ms 13876 KB Output is correct
14 Correct 38 ms 13892 KB Output is correct
15 Correct 18 ms 13264 KB Output is correct
16 Correct 18 ms 13268 KB Output is correct
17 Correct 4 ms 10968 KB Output is correct
18 Correct 4 ms 10968 KB Output is correct
19 Correct 4 ms 10968 KB Output is correct
20 Correct 4 ms 10968 KB Output is correct
21 Correct 5 ms 10964 KB Output is correct
22 Correct 4 ms 10964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 9048 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 13904 KB Output is correct
2 Correct 28 ms 13756 KB Output is correct
3 Correct 27 ms 13912 KB Output is correct
4 Correct 29 ms 13912 KB Output is correct
5 Correct 36 ms 13908 KB Output is correct
6 Correct 42 ms 17544 KB Output is correct
7 Correct 34 ms 16708 KB Output is correct
8 Correct 31 ms 15984 KB Output is correct
9 Correct 29 ms 15196 KB Output is correct
10 Correct 27 ms 13904 KB Output is correct
11 Correct 27 ms 13916 KB Output is correct
12 Correct 27 ms 13768 KB Output is correct
13 Correct 26 ms 13932 KB Output is correct
14 Correct 26 ms 13824 KB Output is correct
15 Correct 23 ms 13788 KB Output is correct
16 Correct 16 ms 13008 KB Output is correct
17 Correct 22 ms 14032 KB Output is correct
18 Correct 27 ms 13892 KB Output is correct
19 Correct 22 ms 13868 KB Output is correct
20 Correct 22 ms 14008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Incorrect 2 ms 8796 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 13916 KB Output is correct
2 Correct 27 ms 13652 KB Output is correct
3 Incorrect 36 ms 14288 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6796 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 5 ms 6748 KB Output is correct
9 Correct 8 ms 6748 KB Output is correct
10 Correct 14 ms 6840 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 3 ms 6788 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 3 ms 6744 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 3 ms 6748 KB Output is correct
20 Correct 2 ms 6788 KB Output is correct
21 Correct 3 ms 6748 KB Output is correct
22 Correct 2 ms 6788 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6744 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 3 ms 6748 KB Output is correct
27 Correct 2 ms 6796 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6788 KB Output is correct
32 Correct 3 ms 7000 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Incorrect 2 ms 8796 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6796 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 5 ms 6748 KB Output is correct
9 Correct 8 ms 6748 KB Output is correct
10 Correct 14 ms 6840 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 3 ms 6788 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 3 ms 6744 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 3 ms 6748 KB Output is correct
20 Correct 2 ms 6788 KB Output is correct
21 Correct 3 ms 6748 KB Output is correct
22 Correct 2 ms 6788 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6744 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 3 ms 6748 KB Output is correct
27 Correct 2 ms 6796 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6788 KB Output is correct
32 Correct 3 ms 7000 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Incorrect 2 ms 8796 KB Output isn't correct
39 Halted 0 ms 0 KB -