Submission #565889

#TimeUsernameProblemLanguageResultExecution timeMemory
565889ngpin04Duathlon (APIO18_duathlon)C++14
0 / 100
141 ms31072 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define TASK "" #define bit(x) (1LL << (x)) #define getbit(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() using namespace std; template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); int rand(int l, int r) { return l + rd() % (r - l + 1); } const int N = 2e5 + 5; const int oo = 1e9; const long long ooo = 1e18; const int mod = 1e9 + 7; // 998244353; const long double pi = acos(-1); vector <int> adj[N]; vector <int> g[N]; vector <int> s; long long ans; int num[N]; int low[N]; int sz[N]; int n,m,comp,node,timer; void dfs(int u) { num[u] = low[u] = ++timer; node++; s.push_back(u); for (int v : adj[u]) { if (num[v]) mini(low[u], num[v]); else { dfs(v); mini(low[u], low[v]); if (low[v] >= num[u]) { comp++; int w; do { w = s.back(); s.pop_back(); g[w].push_back(n + comp); g[n + comp].push_back(w); } while (w != v); g[n + comp].push_back(u); g[u].push_back(n + comp); } } } } void solve(int u, int p = -1) { long long tot = 0; sz[u] = (u <= n); for (int v : g[u]) if (v != p) { solve(v, u); sz[u] += sz[v]; if (u > n) tot += (long long) sz[v] * (sz[v] - 1); } if (u > n) { tot += (long long) (n - sz[u]) * ((n - sz[u]) - 1); ans -= tot * ((int) g[u].size() - 1); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef ONLINE_JUDGE // freopen(TASK".inp","r",stdin); // freopen(TASK".out","w",stdout); #endif cin >> n >> m; 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]) { s.clear(); node = 0; dfs(i); ans += (long long) node * (node - 1) * (node - 2); solve(i); } cout << ans; 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...