# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
797328 | 2023-07-29T09:17:50 Z | radaiosm7 | Duathlon (APIO18_duathlon) | C++ | 1000 ms | 1048576 KB |
#include <bits/stdc++.h> using namespace std; #define X first #define Y second int n, m, i, a, b; long long ans, cc; vector<int> adj[100005]; bool visited[100005]; long long sub[100005]; void dfs1(int x, int p=-1) { visited[x] = true; sub[x] = 1LL; ++cc; for (auto y : adj[x]) { if (y == p) continue; dfs1(y, x); sub[x] += sub[y]; } } void dfs2(int x, int p=-1) { ans += 2LL*(sub[x]-1LL)*(cc-sub[x]); for (auto y : adj[x]) { if (y == p) continue; ans += sub[y]*(sub[x]-1LL-sub[y]); dfs2(y, x); } } int main() { scanf("%d%d", &n, &m); for (i=0; i < m; ++i) { scanf("%d%d", &a, &b); adj[a].push_back(b); adj[b].push_back(a); } ans = 0LL; fill(visited+1, visited+n+1, false); for (i=1; i <= n; ++i) { if (!visited[i]) { cc = 0LL; dfs1(i); dfs2(i); } } printf("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 406 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 406 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1073 ms | 957124 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 2 ms | 2644 KB | Output is correct |
3 | Correct | 2 ms | 2664 KB | Output is correct |
4 | Correct | 2 ms | 2644 KB | Output is correct |
5 | Correct | 2 ms | 2644 KB | Output is correct |
6 | Correct | 2 ms | 2644 KB | Output is correct |
7 | Correct | 2 ms | 2644 KB | Output is correct |
8 | Correct | 2 ms | 2644 KB | Output is correct |
9 | Correct | 2 ms | 2644 KB | Output is correct |
10 | Correct | 2 ms | 2644 KB | Output is correct |
11 | Correct | 2 ms | 2644 KB | Output is correct |
12 | Correct | 2 ms | 2668 KB | Output is correct |
13 | Correct | 2 ms | 2656 KB | Output is correct |
14 | Correct | 2 ms | 2644 KB | Output is correct |
15 | Correct | 2 ms | 2656 KB | Output is correct |
16 | Correct | 1 ms | 2644 KB | Output is correct |
17 | Correct | 2 ms | 2644 KB | Output is correct |
18 | Correct | 2 ms | 2668 KB | Output is correct |
19 | Correct | 2 ms | 2668 KB | Output is correct |
20 | Correct | 2 ms | 2660 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 6756 KB | Output is correct |
2 | Correct | 33 ms | 7884 KB | Output is correct |
3 | Correct | 32 ms | 7940 KB | Output is correct |
4 | Correct | 33 ms | 7972 KB | Output is correct |
5 | Correct | 33 ms | 7884 KB | Output is correct |
6 | Correct | 38 ms | 12124 KB | Output is correct |
7 | Correct | 58 ms | 10652 KB | Output is correct |
8 | Correct | 38 ms | 10012 KB | Output is correct |
9 | Correct | 40 ms | 9268 KB | Output is correct |
10 | Correct | 33 ms | 7960 KB | Output is correct |
11 | Correct | 37 ms | 7900 KB | Output is correct |
12 | Correct | 34 ms | 7956 KB | Output is correct |
13 | Correct | 33 ms | 7884 KB | Output is correct |
14 | Correct | 31 ms | 7780 KB | Output is correct |
15 | Correct | 26 ms | 7508 KB | Output is correct |
16 | Correct | 17 ms | 6484 KB | Output is correct |
17 | Correct | 30 ms | 8276 KB | Output is correct |
18 | Correct | 25 ms | 8288 KB | Output is correct |
19 | Correct | 25 ms | 8256 KB | Output is correct |
20 | Correct | 26 ms | 8208 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2644 KB | Output is correct |
2 | Correct | 2 ms | 2644 KB | Output is correct |
3 | Runtime error | 451 ms | 1048576 KB | Execution killed with signal 9 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 6740 KB | Output is correct |
2 | Correct | 33 ms | 7948 KB | Output is correct |
3 | Runtime error | 564 ms | 1048576 KB | Execution killed with signal 9 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 406 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 406 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |