Submission #1111867

#TimeUsernameProblemLanguageResultExecution timeMemory
1111867PioneerDuathlon (APIO18_duathlon)C++17
100 / 100
91 ms41804 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]; vector<int> g1[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); cnt++; ver[cnt].pb(v); g1[v].pb(cnt); g1[cnt].pb(v); while(ver[cnt].back()!=to){ g1[cnt].pb(st.top()); g1[st.top()].pb(cnt); 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]; int cur=0; void calc(int v,int p=-1){ zs[v]=(v<=n); use[v]=1; for(auto to:g1[v]){ if(to==p)continue; calc(to,v); zs[v]+=zs[to]; if(v>n){ ans-=zs[to]*(zs[to]-1)*(sz(g1[v])-1); } } if(v>n){ ans-=(cur-zs[v])*(cur-zs[v]-1)*(sz(g1[v])-1); } } void calc_sz(int v,int p=-1){ cur+=(v<=n); for(auto to:g1[v]){ if(to==p)continue; calc_sz(to,v); } } void bct(){ cnt=n; for(int i=1;i<=n;i++){ if(!use[i])dfs(i); } for(int i=1;i<=n;i++){ // for(auto to:g1[i])cout<<i<<" "<<to<<"\n"; } memset(use,0,sizeof(use)); for(int i=1;i<=n;i++){ if(!use[i]){ cur=0; calc_sz(i); // cout<<cur<<"\n"; ans+=cur*(cur-1)*(cur-2); calc(i); } } } void solve(){ cin>>n>>m; for(int i=1;i<=m;i++){ int a,b; cin>>a>>b; g[a].pb(b); g[b].pb(a); } bct(); // cout<<n*(n-1)*(n-2)/3<<"\n"; 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...