Submission #548978

#TimeUsernameProblemLanguageResultExecution timeMemory
548978leakedDuathlon (APIO18_duathlon)C++17
10 / 100
946 ms1048576 KiB
#include <bits/stdc++.h> #define f first #define s second #define m_p make_pair #define vec vector #define pb push_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define sz(x) (int)(x).size() #define pw(x) (1LL<<(x)) #define fast_prep ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; typedef pair<int,int> pii; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; typedef unsigned long long ull; //#define int long long template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);} const int N=1e5+1; vec<int> g[N]; vec<int> gr[2*N]; int sz[2*N]; int n; vec<pii> vc; int in[N],fup[N],tt=1; vec<vec<pii>> wo; int cm=1; int siz[N]; void dfs1(int v,int p){ in[v]=fup[v]=tt++; for(auto &z : g[v]){ if(z==p) continue; // cout<< if(in[z]){ umin(fup[v],in[z]); if(in[z]<in[v]) vc.pb({v,z}); } else{ vc.pb({v,z}); dfs1(z,v); if(fup[z]>=in[v]){ vec<pii> cur; while(vc.back()!=m_p(v,z)) cur.pb(vc.back()),vc.pop_back(); cur.pb(vc.back());vc.pop_back(); wo.pb(cur); // cout<<sz(cur)<<endl; } } } } int dp[N]; void dfs2(int v,int p){ dp[v]=(v<=n); // cout<<"WE "<<v<<' '<<dp[v]<<endl; for(auto &z : gr[v]){ if(z==p) continue; dfs2(z,v); dp[v]+=dp[z]; } } ll ans=0; void dfs3(int v,int full,int p){ if(v<=n){ for(auto &z : gr[v]){ if(z!=p){ ans-=1ll*(siz[z]-1)*(full-dp[z])*(full-dp[z]-1); } else{ ans-=1ll*(siz[z]-1)*(dp[v])*(dp[v]-1); } } } for(auto &z : gr[v]) { if(z==p) continue; dfs3(z,full,v); } } void init(){ for(int i=1;i<=n;i++){ if(!in[i]){ dfs1(i,i); if(sz(vc)) wo.pb(vc); vc.clear(); if(!sz(wo)) continue; for(auto &i : wo){ set<int>st; for(auto &j : i) st.insert(j.f),st.insert(j.s); siz[n+cm]=sz(st); for(auto &j : st) gr[n+cm].pb(j),gr[j].pb(n+cm); ++cm; } wo.clear(); // if(!sz(wo)) continue; // cout<<"WO "<<endl; dfs2(n+cm-1,n+cm-1); dfs3(n+cm-1,dp[n+cm-1],-1); ans+=1ll*dp[n+cm-1]*(dp[n+cm-1]-1)*(dp[n+cm-1]-2); } } } signed main(){ fast_prep; int m; cin>>n>>m; for(int i=0;i<m;i++){ int v,u; cin>>v>>u; g[v].pb(u);g[u].pb(v); } init(); cout<<ans; return 0; } /* abbaaa cbbbbccbbccbbbbbbc (((((((()))()))))) 5 5 4 2 2 5 4 1 2 1 4 5 */
#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...