Submission #389434

#TimeUsernameProblemLanguageResultExecution timeMemory
389434phathnvDuathlon (APIO18_duathlon)C++11
100 / 100
149 ms29304 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 7; int n, m, sz, cnt[N], low[N], num[N], timer, numComp; vector<int> adj[N], adj2[N]; stack<int> st; ll answer; void Dfs1(int u){ low[u] = num[u] = ++timer; st.push(u); sz++; for(int v : adj[u]){ if (!num[v]){ Dfs1(v); low[u] = min(low[u], low[v]); if (low[v] == num[u]){ ++numComp; adj2[u].push_back(n + numComp); while (true){ int vex = st.top(); st.pop(); adj2[n + numComp].push_back(vex); if (vex == v) break; } } } else { low[u] = min(low[u], num[v]); } } } void Dfs2(int u){ cnt[u] = (u <= n); for(int v : adj2[u]){ Dfs2(v); cnt[u] += cnt[v]; if (u > n) answer -= (ll) adj2[u].size() * cnt[v] * (cnt[v] - 1); } if (u > n) answer -= (ll) adj2[u].size() * (sz - cnt[u]) * (sz - cnt[u] - 1); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 1; i <= m; i++){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for(int i = 1; i <= n; i++){ if (num[i]) continue; sz = 0; Dfs1(i); Dfs2(i); answer += (ll) sz * (sz - 1) * (sz - 2); } cout << answer; 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...