Submission #136267

#TimeUsernameProblemLanguageResultExecution timeMemory
136267baluteshihDuathlon (APIO18_duathlon)C++14
100 / 100
169 ms24120 KiB
#pragma GCC optimize("O3","unroll-loops") #include <bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; vector<ll> G[100005]; ll low[100005],dfn[100005],avsub[100005],sub[100005],dft; ll ans,c; stack<ll> st; bitset<100005> vis; void con(int u) { vis[u]=1,++c; for(ll i:G[u]) if(!vis[i]) con(i); } void dfs(int u,int f) { ll usq=0; low[u]=dfn[u]=++dft,sub[u]=1,ans+=(c-1)*(c-1),avsub[u]=1; st.push(u); for(ll i:G[u]) if(i!=f) if(!dfn[i]) { dfs(i,u),sub[u]+=sub[i]; if(low[i]>=dfn[u]) { ll sq=0; vector<ll> v; avsub[u]+=sub[i]; for(int x=-1;x!=i;) x=st.top(),st.pop(),sq+=avsub[x]*avsub[x],v.pb(x); for(ll j:v) ans-=(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); ll 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:38:13: warning: unused variable 'j' [-Wunused-variable]
      for(ll j:v)
             ^
count_triplets.cpp:27:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   if(i!=f)
     ^
count_triplets.cpp:23:5: warning: unused variable 'usq' [-Wunused-variable]
  ll usq=0;
     ^~~
#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...