Submission #967865

#TimeUsernameProblemLanguageResultExecution timeMemory
967865socpiteDuathlon (APIO18_duathlon)C++14
0 / 100
130 ms33780 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 2e5+5; vector<int> g[maxn]; int sz[maxn], dp[maxn]; vector<int> blg[maxn]; int low[maxn], num[maxn]; int n, m, bcsz; long long ans = 0; int tdfs; stack<int> stk; void addedge(int a, int b){ // cout << a << " " << b << endl; blg[a].push_back(b); blg[b].push_back(a); } void dfs(int x, int p){ stk.push(x); low[x] = num[x] = ++tdfs; for(auto v:g[x]){ if(v == p)continue; if(num[v])low[x] = min(low[x], num[v]); else { dfs(v, x); low[x] = min(low[x], low[v]); } } if(p){ if(low[x] == num[p]){ bcsz++; while(stk.top() != x){ addedge(stk.top(), bcsz); sz[bcsz]++; stk.pop(); } addedge(x, bcsz); sz[bcsz]++; stk.pop(); addedge(p, bcsz); } else if(low[x] == num[x]){ stk.pop(); bcsz++; sz[bcsz] = 1; addedge(x, bcsz); addedge(p, bcsz); } } } long long dfs2(int x, int p){ dp[x] = (x <= n); long long re = 0; for(auto v: blg[x]){ if(v == p)continue; re += dfs2(v, x); dp[x] += dp[v]; if(x <= n){ re += 1LL*dp[v]*(n - dp[v] - 1); } else { re += 1LL*(blg[x].size()-2)*dp[v]*(n-dp[v]); } } if(x <= n){ re += 1LL*(n - dp[x])*(dp[x] - 1); } else { re += 1LL*(blg[x].size()-2)*(n - dp[x])*(dp[x]); } // cout << "SUS " << x << " " << re << endl; return re; } int main() { cin >> n >> m; while(m--){ int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } bcsz = n; dfs(1, 0); cout << dfs2(1, 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...