제출 #928461

#제출 시각아이디문제언어결과실행 시간메모리
928461TAhmed33철인 이종 경기 (APIO18_duathlon)C++98
100 / 100
76 ms32272 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 25; vector <int> adj[MAXN]; int n, m; int dep[MAXN], low[MAXN]; vector <int> adj2[MAXN]; long long cnt, sze2; long long ans; vector <int> cur; void dfs (int pos, int par, int tt) { dep[pos] = low[pos] = tt; cur.push_back(pos); sze2++; for (auto j : adj[pos]) { if (j == par) continue; if (dep[j] != -1) { low[pos] = min(low[pos], dep[j]); } else { dfs(j, pos, tt + 1); low[pos] = min(low[pos], low[j]); if (low[j] >= dep[pos]) { ++cnt; adj2[pos].push_back(n + cnt); while (adj2[n + cnt].empty() || adj2[n + cnt].back() != j) { adj2[n + cnt].push_back(cur.back()); cur.pop_back(); } } } } } long long sze[MAXN]; void dfs2 (int pos, int par) { if (pos <= n) sze[pos] = 1; long long l = adj2[pos].size(); for (auto j : adj2[pos]) { dfs2(j, pos); sze[pos] += sze[j]; if (pos > n) { ans -= 1ll * sze[j] * (sze[j] - 1) * l; } } if (pos > n) { ans -= 1ll * (sze2 - sze[pos]) * (sze2 - sze[pos] - 1) * l; } } int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } memset(dep, -1, sizeof(dep)); for (int i = 1; i <= n; i++) { if (-1 == dep[i]) { sze2 = 0; cur.clear(); dfs(i, -1, 0); ans += sze2 * (sze2 - 1) * (sze2 - 2); dfs2(i, -1); } } cout << ans << '\n'; }
#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...