Submission #1094140

#TimeUsernameProblemLanguageResultExecution timeMemory
1094140BF001Duathlon (APIO18_duathlon)C++17
100 / 100
72 ms29608 KiB
#include<bits/stdc++.h> using namespace std; #define N 100005 #define int long long int low[N], id[N], cnt, siz[2 * N], n, m, res = 0, bcc, sizncc; vector<int> adj[N], adj2[2 * N]; stack<int> st; void dfs(int u, int p){ low[u] = id[u] = ++cnt; sizncc++; st.push(u); for (auto x : adj[u]){ if (x == p){ p = -1; continue; } if (id[x]){ low[u] = min(low[u], id[x]); } else{ dfs(x, u); low[u] = min(low[u], low[x]); if (low[x] >= id[u]){ bcc++; int s = -1; adj2[u].push_back(bcc); while (s != x){ s = st.top(); st.pop(); low[s] = id[s] = n + 1; adj2[bcc].push_back(s); } } } } } void cal(int u, int p){ int si = (int) adj2[u].size(); siz[u] = (u <= n); for (auto x : adj2[u]){ if (x == p) continue; cal(x, u); siz[u] += siz[x]; if (u > n){ res -= si * siz[x] * (siz[x] - 1); } } if (u > n) res -= si * (sizncc - siz[u]) * (sizncc - siz[u] - 1); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> m; bcc = n; 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 (!id[i]){ sizncc = 0; dfs(i, 0); res += sizncc * (sizncc - 1) * (sizncc - 2); cal(i, 0); } } cout << res; 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...