Submission #1127199

#TimeUsernameProblemLanguageResultExecution timeMemory
1127199czaudernaDuathlon (APIO18_duathlon)C++20
49 / 100
50 ms23868 KiB
// Solve dla całego zadnia // O(n) #include <bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; const int N = 1e5+3; vector<int> grf[N], tree[2*N], stos; ll siz[N], out, ile; int n, pre[N], low[N], tmr, cnt=1; void dfs(int v, int p){ pre[v]=low[v]= ++tmr; ile++; stos.pb(v); for(auto w:grf[v]){ if(w==p) continue; if(!pre[w]){ dfs(w, v); low[v]=min(low[v], low[w]); if(low[w]>= pre[v]){ tree[v].pb(n+cnt); while(tree[n+cnt].size()==0 || tree[n+cnt].back()!=w){ tree[n+cnt].pb(stos.back()); stos.pop_back(); } cnt++; } }else low[v]=min(low[v], pre[w]); } } void dfs2(int v, int p){ if(v<=n) siz[v]=1; for(auto w:tree[v]){ dfs2(w, v); siz[v]+=siz[w]; if(v>n) out-=(ll)tree[v].size()*siz[w]*(siz[w]-1); } if(v>n) out-=(ll)tree[v].size()*(ile-siz[v])*(ile-siz[v]-1); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int m; cin >> n >> m; for(int i=0; i<m; i++){ int a, b; cin >> a >> b; grf[a].pb(b); grf[b].pb(a); } for(int i=1; i<=n; i++){ if(pre[i]) continue; ile=0; dfs(i, i); out+=ile*(ile-1)*(ile-2); dfs2(i, i); } cout << out << '\n'; return 0; }
#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...