Submission #59291

#TimeUsernameProblemLanguageResultExecution timeMemory
59291gabrielsimoesDuathlon (APIO18_duathlon)C++17
23 / 100
178 ms22996 KiB
#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]; bool ok[MAXN]; void dfs0(int cur, int pre) { if (ok[cur]) return; ok[cur] = 1; 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) { if (ok[cur]) return; ok[cur] = 1; 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); for (int i = 0,a,b; i < m; i++) { scanf("%d%d", &a, &b); g[a].push_back(b); g[b].push_back(a); } for (int i = 0; i < n; i++) dfs0(i, i); memset(ok, 0, sizeof(ok)); for (int i = 0; i < n; i++) dfs1(i, i); printf("%lld\n", ans); }

Compilation message (stderr)

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
count_triplets.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~
#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...