제출 #112017

#제출 시각아이디문제언어결과실행 시간메모리
112017jangwonyoung철인 이종 경기 (APIO18_duathlon)C++14
100 / 100
225 ms23932 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back const int N=1e5+1,M=2e5+1; int n,m; int d[N],low[N],vis[N],vis2[N]; vector<int>adj[N],ch[N]; int par[N],sz[N]; int ebc[N]; void dfs(int id,int p){ vis[id]=true; sz[id]=1; d[id]=low[id]=d[p]+1; for(auto cur:adj[id]){ if(cur==p){ par[id]=p;continue; } if(vis[cur]){ low[id]=min(low[id],d[cur]);continue; } ch[id].pb(cur); dfs(cur,id); sz[id]+=sz[cur]; low[id]=min(low[id],low[cur]); } } ll val[N]; int szn; int psz[N]; void dfs2(int id){ psz[id]=szn; vis2[id]=true; if(low[id]<d[id]-1) ebc[id]=ebc[par[id]]; else ebc[id]=id; int pcnt=1; for(auto cur:ch[id]){ dfs2(cur); if(ebc[cur]!=ebc[id]) val[ebc[cur]]+=1LL*(szn-sz[cur])*(szn-sz[cur]); if(ebc[cur]!=ebc[id]) pcnt+=sz[cur]; } val[ebc[id]]+=1LL*pcnt*pcnt; } ll ans; int main(){ ios::sync_with_stdio(false); cin >> n >> m; for(int i=1; i<=m ;i++){ int u,v;cin >> u >> v; adj[u].pb(v);adj[v].pb(u); } for(int i=1; i<=n ;i++){ if(!vis[i]){ dfs(i,0);ans+=1LL*sz[i]*(sz[i]-1)*(sz[i]-1); } } for(int i=1; i<=n ;i++){ if(!vis2[i]) szn=sz[i]; if(!vis2[i]) dfs2(i); } for(int i=1; i<=n ;i++){ int pcnt=1; szn=psz[i]; for(auto cur:ch[i]){ if(ebc[cur]!=ebc[i]) ans+=1LL*(szn-sz[cur])*(szn-sz[cur]); if(ebc[cur]!=ebc[i]) ans-=val[ebc[cur]]; if(ebc[cur]!=ebc[i]) pcnt+=sz[cur]; } ans+=1LL*pcnt*pcnt; ans-=val[ebc[i]]; } cout << ans << endl; }
#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...