제출 #229727

#제출 시각아이디문제언어결과실행 시간메모리
229727lyc철인 이종 경기 (APIO18_duathlon)C++14
100 / 100
173 ms28664 KiB
#include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " :: " << x << endl #define _ << " " << #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(),(x).end() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define RFOR(i,a,b) for (int i=(a);i>=(b);--i) const int MX_N = 1e5+5; const int MX_M = 2e5+5; int N, M; vector<int> al[MX_N]; namespace BCT { int pre[MX_N], low[MX_N], dfc, sz; int stk[MX_N], tp; int wgh[2*MX_N], cnt; vector<int> T[2*MX_N]; int sub[2*MX_N]; long long ans; void Tarjan(int u) { pre[u] = low[u] = ++dfc; stk[++tp] = u; ++sz; for (int v : al[u]) { if (!pre[v]) { Tarjan(v); low[u] = min(low[u],low[v]); if (low[v] == pre[u]) { wgh[++cnt] = 0; for (int x = 0; x != v; --tp) { x = stk[tp]; T[cnt].push_back(x); T[x].push_back(cnt); ++wgh[cnt]; } T[cnt].push_back(u); T[u].push_back(cnt); ++wgh[cnt]; } } else low[u] = min(low[u],pre[v]); } } void dfs(int u, int p) { long long cur = 0; sub[u] = (u<=N); for (int v : T[u]) if (v != p) { dfs(v,u); cur += 2LL * wgh[u] * sub[u] * sub[v]; sub[u] += sub[v]; } cur += 2LL * wgh[u] * sub[u] * (sz - sub[u]); //TRACE(u _ p _ sz _ sub[u] _ cur); ans += cur; } long long solve() { fill_n(pre,N+1,0); dfc = tp = 0; fill_n(wgh,N+1,-1); ans = 0; cnt = N; FOR(i,1,N) if (!pre[i]) { sz = 0; Tarjan(i), --tp; dfs(i,0); } return ans; } void dbg() { FOR(i,1,cnt) { cout << i << " sz " << wgh[i] << " :: "; for (auto& x : T[i]) cout << x << ' '; cout << endl; } } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; FOR(i,1,M){ int U, V; cin >> U >> V; al[U].push_back(V); al[V].push_back(U); } cout << BCT::solve() << '\n'; //BCT::dbg(); }
#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...