Submission #1116949

#TimeUsernameProblemLanguageResultExecution timeMemory
1116949adaawfDuathlon (APIO18_duathlon)C++17
100 / 100
100 ms29616 KiB
#include <iostream> #include <vector> #include <map> using namespace std; map<pair<int, int>, int> mm; vector<int> g[100005], gg[200005], v; int tin[100005], low[100005], z = 0, db[100005], hh; long long int s[200005], f[200005], kk = 0, n, res = 0; void dfs(int x, int p) { tin[x] = low[x] = ++z; v.push_back(x); int c = 0; for (int w : g[x]) { if (w == p) continue; if (tin[w] == 0) { dfs(w, x); low[x] = min(low[x], low[w]); if (low[w] >= tin[x]) { hh++; gg[hh].push_back(x); gg[x].push_back(hh); while (1) { int h = v.back(); gg[h].push_back(hh); gg[hh].push_back(h); v.pop_back(); if (h == w) break; } } c++; } else low[x] = min(low[x], tin[w]); } if (p == -1 && c >= 2) { } } void dfs3(int x, int p) { db[x] = 1; if (x <= n) kk++; for (int w : gg[x]) { if (w == p) continue; dfs3(w, x); } } void dfs4(int x, int p) { s[x] = (x <= n); for (int w : gg[x]) { if (w == p) continue; dfs4(w, x); s[x] += s[w]; if (x > n) res -= s[w] * (s[w] - 1) * (gg[x].size() - 1); } if (x > n) res -= (kk - s[x]) * (kk - s[x] - 1) * (gg[x].size() - 1); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int m; cin >> n >> m; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } hh = n; for (int i = 1; i <= n; i++) { if (tin[i] == 0) { dfs(i, -1); } } for (int i = 1; i <= n; i++) { if (db[i] == 0) { kk = 0; dfs3(i, -1); res += kk * (kk - 1) * (kk - 2); dfs4(i, -1); } } cout << res; }
#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...