Submission #969444

#TimeUsernameProblemLanguageResultExecution timeMemory
969444c2zi6Duathlon (APIO18_duathlon)C++14
100 / 100
75 ms28504 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(), (a).end() #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i) #define reprl(i, a, b) for (int i = int(a); i >= int(b); --i) #define rep(i, n) for (int i = 0; i < int(n); ++i) #define mkp(a, b) make_pair(a, b) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<VPI> VVPI; typedef pair<ll, ll> PLL; typedef vector<ll> VL; typedef vector<PLL> VPL; typedef vector<VL> VVL; typedef vector<VVL> VVVL; typedef vector<VPL> VVPL; template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;} template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<class T> using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int n, m; int bcc; VVI initgp, bccgp; VI vis, low, num; int tc; stack<int> st; void tarjan(int u, int p = -1) { st.push(u); vis[u] = 1; low[u] = num[u] = tc++; for (int v : initgp[u]) if (v != p) { if (vis[v] == 1) { setmin(low[u], num[v]); } else if (vis[v] == 0) { tarjan(v, u); setmin(low[u], low[v]); if (low[v] >= num[u]) { bccgp[u].pb(n+bcc); while (st.top() != v) { bccgp[n+bcc].pb(st.top()); st.pop(); } bccgp[n+bcc].pb(st.top()); st.pop(); bcc++; } } } vis[u] = 2; } ll ans; VI sub; void dfs(int u, int p = -1) { sub[u] = (u < n); for (int v : bccgp[u]) if (v != p) { dfs(v); sub[u] += sub[v]; if (u >= n) ans -= 1ll * bccgp[u].size() * sub[v] * (sub[v]-1); } if (u >= n) ans -= 1ll * bccgp[u].size() * (tc-sub[u]) * (tc-sub[u]-1); } void solve() { cin >> n >> m; initgp = VVI(n); bccgp = VVI(2*n); rep(i, m) { int u, v; cin >> u >> v; u--, v--; initgp[u].pb(v); initgp[v].pb(u); } vis = low = num = VI(n); sub = VI(2*n); bcc = 0; ans = 0; rep(u, n) if (!vis[u]) { tc = 0; tarjan(u); ans += 1ll * tc * (tc-1) * (tc-2); dfs(u); } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while (t--) solve(); }
#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...