Submission #405081

# Submission time Handle Problem Language Result Execution time Memory
405081 2021-05-15T16:46:10 Z BERNARB01 Duathlon (APIO18_duathlon) C++17
0 / 100
1000 ms 1048580 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	vector<long long> sbt(n, 0);
	long long ans = 0;
	function<void(int, int)> dfs0 = [&](int u, int p) {
		sbt[u] = 1;
		for (int v : g[u]) {
			if (v != p) {
				dfs0(v, u);
				sbt[u] += sbt[v];
			}
		}
		long long sum = n - 1;
		long long sbtp = n - sbt[u];
		ans += sbtp * 1LL * (sum - sbtp);
		for (int v : g[u]) {
			if (v != p) {
				ans += sbt[v] * 1LL * (sum - sbt[v]);
			}
		}
	};
	for (int i = 0; i < n; i++) {
		if (sbt[i] == 0) {
			dfs0(i, -1);
		}
	}
	cout << ans << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 550 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 550 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 709208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Incorrect 1 ms 316 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 7608 KB Output is correct
2 Correct 54 ms 7108 KB Output is correct
3 Correct 58 ms 7064 KB Output is correct
4 Correct 49 ms 7108 KB Output is correct
5 Correct 58 ms 7228 KB Output is correct
6 Correct 70 ms 13016 KB Output is correct
7 Correct 81 ms 11036 KB Output is correct
8 Correct 55 ms 10052 KB Output is correct
9 Correct 59 ms 8972 KB Output is correct
10 Incorrect 49 ms 7132 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Runtime error 719 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 7668 KB Output is correct
2 Correct 58 ms 7084 KB Output is correct
3 Runtime error 941 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 550 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 550 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -