# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
59290 | 2018-07-21T12:01:46 Z | gabrielsimoes | Duathlon (APIO18_duathlon) | C++17 | 170 ms | 23828 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e5+10; const int MAXM = 2e5+10; int n, m; vector<int> g[MAXN]; ll sub[MAXN]; void dfs0(int cur, int pre) { sub[cur] = 1; for (int nx : g[cur]) { if (nx != pre) { dfs0(nx, cur); sub[cur] += sub[nx]; } } } ll ans = 0; void dfs1(int cur, int pre, ll sum = 0) { ans += 2 * sum * (sub[cur]-1); // printf("dfs1 %d %lld %lld: ans %lld\n", cur, sum, sub[cur], ans); for (int nx : g[cur]) { if (nx != pre) { ans += (sub[cur]-1-sub[nx]) * sub[nx]; dfs1(nx, cur, sum + sub[cur] - sub[nx]); // printf("dfs1 %d: ans %lld\n", cur, ans); } } } int main() { scanf("%d%d", &n, &m); assert(m == n-1); for (int i = 0,a,b; i < m; i++) { scanf("%d%d", &a, &b); g[a].push_back(b); g[b].push_back(a); } dfs0(1, 1); dfs1(1, 1); printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 5240 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 5240 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 11 ms | 5352 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5432 KB | Output is correct |
2 | Correct | 5 ms | 5564 KB | Output is correct |
3 | Correct | 6 ms | 5700 KB | Output is correct |
4 | Correct | 6 ms | 5776 KB | Output is correct |
5 | Correct | 7 ms | 5908 KB | Output is correct |
6 | Correct | 6 ms | 5908 KB | Output is correct |
7 | Correct | 6 ms | 5908 KB | Output is correct |
8 | Correct | 6 ms | 5908 KB | Output is correct |
9 | Correct | 5 ms | 5908 KB | Output is correct |
10 | Runtime error | 11 ms | 5908 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 104 ms | 11124 KB | Output is correct |
2 | Correct | 164 ms | 12440 KB | Output is correct |
3 | Correct | 119 ms | 13576 KB | Output is correct |
4 | Correct | 100 ms | 14752 KB | Output is correct |
5 | Correct | 102 ms | 16068 KB | Output is correct |
6 | Correct | 145 ms | 20712 KB | Output is correct |
7 | Correct | 170 ms | 20740 KB | Output is correct |
8 | Correct | 144 ms | 21552 KB | Output is correct |
9 | Correct | 169 ms | 22212 KB | Output is correct |
10 | Runtime error | 9 ms | 22212 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 22212 KB | Output is correct |
2 | Correct | 5 ms | 22212 KB | Output is correct |
3 | Runtime error | 9 ms | 22212 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 139 ms | 22512 KB | Output is correct |
2 | Correct | 135 ms | 23828 KB | Output is correct |
3 | Runtime error | 10 ms | 23828 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 5240 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 5240 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |