Submission #1234234

#TimeUsernameProblemLanguageResultExecution timeMemory
1234234JerDuathlon (APIO18_duathlon)C++20
0 / 100
1115 ms1114112 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 100005; vector<int> con[MAXN]; vector<int> parent(MAXN, 0); vector<int> depth(MAXN, 0); void find_depth(int curr, int par, int d) { parent[curr] = par; depth[curr] = d; for (auto i : con[curr]) { if (i == par) continue; find_depth(i, curr, d + 1); } } int lca(int u, int v) { while (depth[u] > depth[v]) u = parent[u]; while (depth[v] > depth[u]) v = parent[v]; while (u != v) { u = parent[u]; v = parent[v]; } return u; } int distance(int u, int v) { int l = lca(u, v); return depth[u] + depth[v] - 2 * depth[l]; } int n, m; int main() { scanf("%d%d", &n, &m); int a, b; for (int i = 0; i < m; i++) scanf("%d%d", &a, &b), con[a].push_back(b), con[b].push_back(a); find_depth(1, 1, 0); ll res = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { int dist = distance(i, j); if (dist >= 2) res += dist - 1; } printf("%lld\n", res); return 0; }

Compilation message (stderr)

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
count_triplets.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         scanf("%d%d", &a, &b), con[a].push_back(b), con[b].push_back(a);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...