Submission #368941

#TimeUsernameProblemLanguageResultExecution timeMemory
368941YJUDuathlon (APIO18_duathlon)C++14
0 / 100
170 ms66144 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector,Ofast") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll MOD=1e9+7; const ll MOD2=998244353; const ll N=1e6+5; const ld pi=acos(-1); const ll INF=(1LL<<60); #define SQ(i) ((i)*(i)) #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(_a) (ll)_a.size() ll n,m,x,y; ll low[N],depth[N],cnt=0,ptr,w[N],ans,sz[N]; vector<ll> G[N],v[N]; ll stk[N],now; void DFS1(ll nd,ll pa){ ++cnt; low[nd]=depth[nd]=depth[pa]+1; stk[++now]=nd; for(ll i:v[nd]){ if(i==pa)continue; if(depth[i]){ low[nd]=min(low[nd],depth[i]); }else{ // // DFS1(i,nd); if(low[i]==depth[nd]){ //cout<<"FIND BCC\n"; ++ptr; while(stk[now]!=nd){ //cout<<stk[now]<<" "; ++w[ptr];w[stk[now]]=-1; G[stk[now]].pb(ptr); G[ptr].pb(stk[now]); --now; } //cout<<stk[now]<<"\n"; ++w[ptr];w[stk[now]]=-1; G[stk[now]].pb(ptr); G[ptr].pb(stk[now]); } low[nd]=min(low[nd],low[i]); } } } void DFS2(ll nd,ll pa){ sz[nd]=(nd<=n?1:0); for(auto i:G[nd]){ if(i==pa)continue; DFS2(i,nd); ans+=2*w[nd]*sz[nd]*sz[i]; sz[nd]+=sz[i]; } ans+=2*w[nd]*sz[nd]*(cnt-sz[nd]); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; ptr=n; REP(i,m){ cin>>x>>y; v[x].pb(y),v[y].pb(x); } REP1(i,n){ if(!depth[i]){ cnt=now=0; DFS1(i,0); DFS2(i,0); } } cout<<ans<<"\n"; return 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...