Submission #136275

#TimeUsernameProblemLanguageResultExecution timeMemory
136275baluteshihDuathlon (APIO18_duathlon)C++14
100 / 100
147 ms15632 KiB
#pragma GCC optimize("O3","unroll-loops") #include <bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; vector<int> G[100005]; int low[100005],dfn[100005],avsub[100005],sub[100005],st[100005],top=-1,dft; ll ans,c; bitset<100005> vis; void con(int u) { vis[u]=1,++c; for(int i:G[u]) if(!vis[i]) con(i); } void dfs(int u,int f) { low[u]=dfn[u]=++dft,sub[u]=1,ans+=(c-1)*(c-1),avsub[u]=1,st[++top]=u; for(int i:G[u]) if(i!=f) if(!dfn[i]) { dfs(i,u),sub[u]+=sub[i]; if(low[i]>=dfn[u]) { ll sq=0,sz=0; avsub[u]+=sub[i]; for(int x=-1;x!=i;) x=st[top--],sq+=(ll)avsub[x]*avsub[x],++sz; ans-=sz*((c-sub[i])*(c-sub[i])+sq); } else low[u]=min(low[u],low[i]); } else if(dfn[u]>dfn[i]) low[u]=min(low[u],dfn[i]); } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int m,a,b,n; cin >> n >> m; while(m--) cin >> a >> b,G[a].pb(b),G[b].pb(a); for(int i=1;i<=n;++i) if(!vis[i]) c=0,con(i),dfs(i,i); cout << ans << "\n"; }

Compilation message (stderr)

count_triplets.cpp: In function 'void dfs(int, int)':
count_triplets.cpp:24:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   if(i!=f)
     ^
#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...