# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
797312 | 2023-07-29T09:09:05 Z | radaiosm7 | Duathlon (APIO18_duathlon) | C++ | 992 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) { 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) { ans += 2LL*(sub[x]-1LL)*(cc-sub[x]); for (auto y : adj[x]) { if (y == p) continue; 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, -1); dfs2(i, -1); } } printf("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 590 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 590 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 992 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 32 ms | 7964 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 2664 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 44 ms | 7888 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 590 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 590 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |