Submission #721866

#TimeUsernameProblemLanguageResultExecution timeMemory
721866SonDuathlon (APIO18_duathlon)C++14
100 / 100
125 ms28204 KiB
#include <bits/stdc++.h> using namespace std; #define LL long long #define pb push_back int n,m; vector < int > E[100005]; int low[100005], num[100005]; int idx = 0; vector < int > bcc_group[200005]; int bccs = 1; vector < int > stck; int N = 0, sub[200005]; LL ans = 0; void dfs1( int u, int p ){ low[u] = num[u] = ++idx; stck.pb(u); N++; for ( int v : E[u] ){ if ( num[v] ) low[u] = min( low[u], num[v] ); else { dfs1(v,u); low[u] = min(low[u], low[v]); if ( low[v] >= num[u] ){ bcc_group[u].pb(n + bccs); while ( !bcc_group[n+bccs].size() || bcc_group[n+bccs].back() != v ){ bcc_group[n+bccs].pb(stck.back()); stck.pop_back(); } bccs++; } } } } void dfs2( int u ){ sub[u] = (u <= n); for ( int v : bcc_group[u] ){ dfs2(v); sub[u] += sub[v]; if ( u > n ) ans -= bcc_group[u].size() * 1LL * (sub[v]) * (sub[v]-1); } if (u > n){ ans -= bcc_group[u].size() * 1LL * (N-sub[u]) * (N - sub[u] - 1); } } int main(){ scanf("%d%d",&n,&m); for ( int i = 1; i <= m; i++ ){ int u , v; scanf("%d%d",&u,&v); E[u].pb(v); E[v].pb(u); } for ( int i = 1; i <= n; i++ ){ if ( num[i] == 0 ){ N = 0; dfs1(i,-1); ans += N * 1LL * (N-1) * (N-2); dfs2(i); } } printf("%lld\n",ans); return 0; }

Compilation message (stderr)

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     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",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~
#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...