제출 #50065

#제출 시각아이디문제언어결과실행 시간메모리
50065tmwilliamlin168철인 이종 경기 (APIO18_duathlon)C++14
100 / 100
191 ms28412 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int mxN=1e5; int n, m, dt=1, tin[mxN], low[mxN], st[mxN], sth, bccI; vector<int> adj1[mxN], adj2[2*mxN]; ll sz[2*mxN], n2, ans; void dfs1(int u, int p) { tin[u]=low[u]=dt++; st[sth++]=u; ++n2; for(int v : adj1[u]) { if(!tin[v]) { dfs1(v, u); low[u]=min(low[v], low[u]); if(low[v]>=tin[u]) { adj2[u].push_back(bccI+n); while(adj2[bccI+n].empty()||adj2[bccI+n].back()!=v) adj2[bccI+n].push_back(st[--sth]); ++bccI; } } else if(v!=p) low[u]=min(tin[v], low[u]); } } void dfs2(int u, int p) { // cout << "d21 " << u << " " << p << endl; sz[u]=u<n; for(int v : adj2[u]) { dfs2(v, u); sz[u]+=sz[v]; if(u>=n) ans-=(adj2[u].size()-(p==-1))*sz[v]*(sz[v]-1); } if(u>=n) ans-=adj2[u].size()*(n2-sz[u])*(n2-sz[u]-1); // cout << "d29 " << u << " " << p << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; while(m--) { int u, v; cin >> u >> v, --u, --v; adj1[u].push_back(v); adj1[v].push_back(u); } for(int i=0; i<n; ++i) { if(tin[i]) continue; dfs1(i, -1); ans+=n2*(n2-1)*(n2-2); dfs2(i, -1); n2=0; } cout << ans; }
#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...