제출 #440026

#제출 시각아이디문제언어결과실행 시간메모리
440026KULIKOLD철인 이종 경기 (APIO18_duathlon)C++17
0 / 100
77 ms16300 KiB
//#pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' const int DIM = 1E5+7; const int INF = 1E9; vector<int> G[DIM],NG[DIM]; int depth[DIM],sz[DIM],P[DIM],vis[DIM],sub[DIM]; ll dp[DIM]; int fcmp(int v,int par){ depth[v] = depth[par]+1; int mi = depth[v]; for(auto to:G[v]){ if (to==par) continue; if (depth[to]){ if (depth[to]<depth[v]) mi = min(mi,depth[to]); continue; } mi = min(mi,fcmp(to,v)); } if (v!=par && mi<=depth[par]) P[v] = par; else P[v] = v; return mi; } int F(int x){ return x==P[x]?x:P[x] = F(P[x]); } ll res = 0,ans = 0; void dfs(int v){ vis[v] = 1; dp[v] = ll(sz[v]-1)*(sz[v]-2) + sz[v] - 1; ans+=ll(sz[v])*(sz[v]-1)*(sz[v]-2); sub[v] = sz[v]; for(auto to:G[v]){ if (vis[to]) continue; dfs(to); res+=dp[to]*sub[v]+dp[v]*sub[to]; dp[v] = dp[v]+dp[to]+ll(sz[v])*sub[to]; sub[v]+=sz[to]; } } int solve(){ int n,m; cin>>n>>m; for(int i = 1;i<=m;++i){ ll u,v; cin>>u>>v; G[u].push_back(v); G[v].push_back(u); } // del for(int i = 1;i<=n;++i) sz[i] = 1; /*for(int i = 1;i<=n;++i){ if (!P[i]) { fcmp(i, i); } } for(int i = 1;i<=n;++i){ ++sz[F(i)]; for(auto to:G[i]) if (F(to)!=F(i)) NG[F(to)].push_back(F(i)),NG[F(i)].push_back(F(to)); } swap(G,NG); */ for(int i = 1;i<=n;++i){ if (sz[i] && !vis[i]) dfs(i); } cout<<res*2+ans<<endl; return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); 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...