Submission #374600

# Submission time Handle Problem Language Result Execution time Memory
374600 2021-03-07T14:16:23 Z morato Duathlon (APIO18_duathlon) C++17
0 / 100
1000 ms 1048580 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

long long ans;
vector<int> adj[N];
int subtree[N], n;

void dfs(int v, int p = 0) {
	subtree[v] = 1;
	for (int u : adj[v]) if (u != p) {
		dfs(u, v);
		subtree[v] += subtree[u];
	}
	long long aux = (v == 1 ? 0ll :  1ll * (n - subtree[v]));
	vector<long long> pref;
	pref.push_back(aux);
	long long local_ans = 0;
	for (int u : adj[v]) if (u != p) {
		assert(!pref.empty());
		local_ans += pref.back() * 1ll * subtree[u];
		pref.push_back(pref.back() + 1ll * subtree[u]);
	}
	ans += 2ll * local_ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m; cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(1);
	cout << ans << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 660 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 660 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1134 ms 628840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2796 KB Output is correct
5 Correct 2 ms 2796 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 2 ms 2796 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Incorrect 2 ms 2668 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 6292 KB Output is correct
2 Correct 79 ms 6252 KB Output is correct
3 Correct 63 ms 6252 KB Output is correct
4 Correct 63 ms 6252 KB Output is correct
5 Correct 67 ms 6252 KB Output is correct
6 Correct 81 ms 13932 KB Output is correct
7 Correct 77 ms 11348 KB Output is correct
8 Correct 80 ms 10084 KB Output is correct
9 Correct 70 ms 8812 KB Output is correct
10 Incorrect 52 ms 6252 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Runtime error 972 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 6252 KB Output is correct
2 Correct 67 ms 6252 KB Output is correct
3 Execution timed out 1151 ms 846556 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 660 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 660 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -