Submission #1127195

#TimeUsernameProblemLanguageResultExecution timeMemory
1127195czaudernaDuathlon (APIO18_duathlon)C++20
23 / 100
1128 ms1114112 KiB
#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[N]; int pre[N], low[N], cnt; ll siz[N], out, ile; bool odw[N]; void dfs(int v, int p){ odw[v]=1; ile++; for(auto w:grf[v]){ if(w==p) continue; dfs(w, v); siz[v]+=siz[w]; } siz[v]++; } void dfs2(int v, int p){ for(auto w:grf[v]){ if(w==p) continue; dfs2(w, v); } if(v!=p) out-=(siz[v]*(siz[v]-1) + (ile-siz[v])*(ile-siz[v]-1)); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, 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(odw[i]) continue; ile=0; dfs(i, i); dfs2(i, i); out+=ile*(ile-1)*(ile-2); } 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...