Submission #1111618

#TimeUsernameProblemLanguageResultExecution timeMemory
1111618PioneerDuathlon (APIO18_duathlon)C++17
0 / 100
91 ms44228 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define ll long long #define int ll #define all(v) v.begin(),v.end() #define sz(s) ((int)s.size()) #define pb push_back #define F first #define S second #define pii pair<int,int> #define ppb pop_back #define lb lower_bound #define ub upper_bound using namespace std; const ll inf=1e18; const int MAX=2e5+10; const int mod=1e9+7; int binpow(int a,int n){ if(!n)return 1; if(n%2==1)return a*binpow(a,n-1)%mod; int k=binpow(a,n/2); return k*k%mod; } int n,m; vector<int> g[MAX]; int tin[MAX],timer; int fup[MAX]; bool use[MAX],cutPoint[MAX]; stack<int> st; vector<int> ver[MAX]; int cmp[MAX],cnt; void dfs(int v,int p=-1){ st.push(v); tin[v]=fup[v]=++timer; use[v]=1; int children=0; for(auto to:g[v]){ if(to==p)continue; if(!use[to]){ children++; dfs(to,v); fup[v]=min(fup[v],fup[to]); if(fup[to]>=tin[v]){ cutPoint[v]=(p!=-1); ver[++cnt].pb(v); while(ver[cnt].back()!=to){ ver[cnt].pb(st.top()); st.pop(); } } } else fup[v]=min(fup[v],tin[to]); } if(p==-1&&children>1){ cutPoint[v]=1; } } int ans; int zs[MAX]; vector<vector<int>> t; void calc(int v,int p=-1){ int in=zs[v]; ans+=in*(in-1)*(in-2); ans+=2*in*(in-1)*(n-in); if(in>=2)ans+=sz(t[v])*in*(in-1); // cout<<v<<" "<<zs[v]<<"\n"; // cout<<v<<" "<<2*in*(in-1)*(n-in)<<"\n"; for(auto to:t[v]){ if(to==p)continue; calc(to,v); zs[v]+=zs[to]; } // cout<<v<<" "<<n-zs[v]<<" "<<zs[v]-in<<" "<<in<<"\n"; ans+=(n-zs[v])*(zs[v]-in)*in; for(auto to:t[v]){ if(to==p)continue; // cout<<v<<" "<<zs[to]<<" "<<n-zs[to]-in<<" "<<in<<"\n"; ans+=zs[to]*(n-zs[to]-in)*in; } } void bct(){ for(int i=1;i<=n;i++){ if(!use[i])dfs(i); } int ck=0; for(int i=1;i<=n;i++){ if(cutPoint[i]){ zs[ck]=1; cmp[i]=ck++; t.pb({}); } } // cout<<cnt<<" "<<cutPoint[1]<<"\n"; for(int i=1;i<=cnt;i++){ t.pb({}); for(int v:ver[i]){ if(!cutPoint[v]){ cmp[v]=ck; zs[ck]++; } else{ t[cmp[v]].pb(ck); t[ck].pb(cmp[v]); } } ck++; } // for(int i=0;i<sz(t);i++){ // cout<<zs[i]<<" "; // } // cout<<"\n"; for(int i=0;i<sz(t);i++){ sort(all(t[i])); t[i].erase(unique(all(t[i])),t[i].end()); } calc(0); } void solve(){ cin>>n>>m; for(int i=1;i<=n;i++){ int a,b; cin>>a>>b; g[a].pb(b); g[b].pb(a); } bct(); cout<<ans<<"\n"; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--)solve(); }
#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...