Submission #369830

#TimeUsernameProblemLanguageResultExecution timeMemory
369830abc864197532Duathlon (APIO18_duathlon)C++17
31 / 100
216 ms45664 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define pb push_back #define eb emplace_back #define test(x) cout << "Line(" << __LINE__ << ") " #x << ' ' << x << endl #define printv(x) {\ for (auto i : x) cout << i << ' ';\ cout << endl;\ } #define pii pair <int, int> #define pll pair <lli, lli> #define X first #define Y second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() template<typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a){ return o << a.X << ' ' << a.Y; } template<typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a){ return o >> a.X >> a.Y; } const int mod = 1e9 + 7, abc = 864197532, N = 100000, logN = 17, K = 333; vector <int> adj[N], bcc[N], cnt[N]; int low[N], dep[N], nbcc = 0; bool vis[N], cut[N]; stack <int> stk; void dfs(int v, int pa) { vis[v] = true; low[v] = dep[v] = ~pa ? dep[pa] + 1 : 0; stk.push(v); int ch = 0; for (int u : adj[v]) if (u != pa) { if (vis[u]) low[v] = min(low[v], dep[u]); else { dfs(u, v); low[v] = min(low[v], low[u]); ch++; if (low[u] >= dep[v]) { cut[v] = true; int x; do { x = stk.top(); stk.pop(); bcc[x].pb(nbcc); cnt[nbcc].pb(x); } while (x != u); cnt[nbcc].pb(v); bcc[v].pb(nbcc++); } } } if (pa == -1 && ch < 2) cut[v] = false; } vector <int> newadj[N * 2]; bool vis2[N * 2]; int sz[N * 2], p[N * 2], val[N * 2]; vector <int> cc; lli C2(int n) { return 1ll * n * (n - 1); } void dfs2(int v, int pa) { sz[v] = val[v]; vis2[v] = true; p[v] = pa; cc.pb(v); for (int u : newadj[v]) if (u != pa) { dfs2(u, v); sz[v] += sz[u]; } } int main () { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0, u, v; i < m; ++i) { cin >> u >> v, --u, --v; adj[u].pb(v); adj[v].pb(u); } for (int i = 0; i < n; ++i) if (!vis[i]) dfs(i, -1); for (int i = 0; i < n; ++i) if (cut[i]) { for (int j : bcc[i]) { newadj[i].pb(j + N); newadj[j + N].pb(i); } } for (int i = 0; i < nbcc; ++i) { for (int j : cnt[i]) { if (!cut[j]) val[i + N]++; } } for (int i = 0; i < n; ++i) if (cut[i]) val[i]++; lli ans = 0; for (int i = N; i < nbcc + N; ++i) if (!vis2[i]) { dfs2(i, -1); int m = sz[i]; if (m <= 2) continue; ans += C2(m - 1) * m; for (int j : cc) { if (j < n) { for (int k : newadj[j]) { if (k == p[j]) ans -= C2(m - sz[j] - val[k]); else ans -= C2(sz[k] - val[k]); } } else { for (int k : newadj[j]) { if (k == p[j]) ans -= C2(m - sz[j]) * val[j]; else ans -= C2(sz[k]) * val[j]; } } } cc.clear(); } cout << ans << endl; }
#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...