Submission #1111182

#TimeUsernameProblemLanguageResultExecution timeMemory
1111182vjudge2Duathlon (APIO18_duathlon)C++17
0 / 100
77 ms28860 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e5 + 10; vector<int> adj[N], g[N << 1], stk; int n, m, st[N], low[N], timer = 0, k, we[N << 1], sz[N << 1], ans = 0; void dfs(int u) { low[u] = st[u] = ++timer; stk.push_back(u); for (auto& v : adj[u]) { if (!st[v]) { dfs(v); low[u] = min(low[u], low[v]); if (low[v] == st[u]) { ++k; for (int x = -1; x != v; stk.pop_back()) { x = stk.back(); g[k].push_back(x); g[x].push_back(k); we[k]++; } g[k].push_back(u); g[u].push_back(k); we[k]++; } } low[u] = min(low[u], st[v]); } } void comp(int u, int p) { sz[u] = (u <= n); int sum = 0, ch = 0; for (int v : g[u]) { if (v == p) continue; ++ch; comp(v, u); sz[u] += sz[v]; sum += sz[v]; } if (!ch) ans--; for (int v : g[u]) if (v != p) ans += we[u] * sz[v] * (sum - sz[v]); ans += we[u] * sum * (n - sum); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; k = 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++) we[i] = -1; dfs(1); comp(1, -1); cout << ans - 1 << '\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...