Submission #997644

#TimeUsernameProblemLanguageResultExecution timeMemory
997644vjudge1Duathlon (APIO18_duathlon)C++17
100 / 100
63 ms33252 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 2e5 + 2; ll ans = 0; int num[N + 2], low[N + 2], timer , n , m , scc; stack < int > st; vector < int > adj[N + 2] , g[N + 2]; ll sz[N + 2]; int mN; void dfs(int u , int p = - 1){ low[u] = num[u] = ++timer; st.push(u); for(auto v: adj[u]){ if(v == p)continue; if(!num[v]){ dfs(v , u); low[u] = min(low[u] , low[v]); if(low[v] >= num[u]){ scc ++; g[scc].push_back(u); g[u].push_back(scc); int y; do{ y = st.top(); st.pop(); g[y].push_back(scc); g[scc].push_back(y); }while(y != v); } } else{ low[u] = min(low[u] , num[v]); } } } ll three_im(ll x , ll z){ if(x < z)return 0; ll k = 1; for(ll i = x ;i >= x - z + 1; i --){ k *= i; } return k ; } ll cal(ll f , ll k){ return three_im(f , 2) * (k - 1); } void dfs2(int u , int p = - 1){ if(u <= n)sz[u] ++; for(auto v: g[u]){ if(v == p)continue; dfs2(v , u); sz[u] += sz[v]; } if(u <= n)return ; ll oth = mN - sz[u] ; for(auto v: g[u]){ if(v == p) continue; ans -= cal(sz[v] , g[u].size()); } ans -= cal(oth , g[u].size()); } void solve() { cin >> n >> m; scc = 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++){ if(!num[i]){ mN = timer; dfs(i); mN = timer - mN; ans += three_im(mN, 3); dfs2(i); } } cout << ans; } signed main() { ios::sync_with_stdio(0), cin.tie(0); #define _ "minrect." if (fopen(_ "inp", "r")) { freopen(_ "inp", "r", stdin); freopen(_ "out", "w", stdout); } solve(); }

Compilation message (stderr)

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(_ "inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(_ "out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...