Submission #1032812

#TimeUsernameProblemLanguageResultExecution timeMemory
1032812vjudge1Duathlon (APIO18_duathlon)C++17
100 / 100
94 ms30116 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define vt vector #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define pb push_back typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; template<class T> bool chmin(T& a, const T& b) { return b<a?a=b, 1:0; } template<class T> bool chmax(T& a, const T& b) { return a<b?a=b, 1:0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int n, m; cin >> n >> m; vt<vt<int>> g(n+1); rep(i, 0, m) { int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } int nc=n; vt<int> stk; vt<int> low(n+1), id(n+1); vt<vt<int>> adj(n+m+1); int tim=0; auto dfs = [&](int at, int par, auto &&dfs) -> void { id[at]=low[at]=++tim; stk.pb(at); for(int to:g[at]) { if(to == par)continue; if(!id[to]) { dfs(to, at, dfs); chmin(low[at], low[to]); if(low[to] >= id[at]) { nc++; adj[nc].pb(at); adj[at].pb(nc); // cout << at << " "; while(1) { int tmp = stk.back(); adj[tmp].pb(nc); adj[nc].pb(tmp); // cout << tmp << " "; stk.pop_back(); if(tmp==to)break; } // cout << endl; } } else low[at] = min(low[at], id[to]); } }; for(int i = 1;i<=n;i++) { if(!id[i]) dfs(i, i, dfs); } vt<int> dp(n+m+1); ll ans=0; vt<bool> vis(n+m+1); auto dfs2 = [&](int at, int par, auto &&dfs2) -> void { if(at <= n)dp[at]=1; vis[at]=1; for(int to:adj[at]) { if(to==par)continue; dfs2(to, at, dfs2); dp[at]+=dp[to]; } }; int sss; auto dfs3 = [&](int at, int par, auto &&dfs3) -> void { if(at <= n) { ll sum=sss-dp[at]; for(int to:adj[at]) { if(to==par)continue; dfs3(to, at, dfs3); ans+=2ll*dp[to]*sum; sum+=dp[to]; } } else { ll sum=sss-dp[at]; ll cnt2=0; for(int to:adj[at]) { if(to==par)continue; dfs3(to, at, dfs3); cnt2+=2ll*dp[to]*sum; sum+=dp[to]; } ans+=cnt2*(sz(adj[at])-2); } }; rep(i, 1, n+1) { if(!vis[i]) { dfs2(i, i, dfs2); sss=dp[i]; dfs3(i, i, dfs3); } } 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...