Submission #546790

#TimeUsernameProblemLanguageResultExecution timeMemory
546790MonarchuwuDuathlon (APIO18_duathlon)C++17
8 / 100
26 ms2384 KiB
#include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int N = 1e5 + 9; int n, m, deg[N]; int par[N]; int root(int u) { return par[u] < 0 ? u : par[u] = root(par[u]); } void Union(int u, int v) { if ((u = root(u)) == (v = root(v))) return; if (par[u] > par[v]) swap(u, v); par[u] += par[v]; par[v] = u; } ll calc2(int n) { return (ll)n * (n - 1) * (n - 2); } ll calc(int n) { return calc2(n) / 3; } bool f[N]; int main() { cin.tie(NULL)->sync_with_stdio(false); cin >> n >> m; fill(par + 1, par + n + 1, -1); for (int i = 0, u, v; i < m; ++i) { cin >> u >> v; Union(u, v); ++deg[u], ++deg[v]; } for (int i = 1; i <= n; ++i) if (deg[i] == 1) f[root(i)] = true; ll ans(0); for (int i = 1; i <= n; ++i) if (par[i] < 0) ans += f[i] ? calc(-par[i]) : calc2(-par[i]); cout << ans << '\n'; } /** /\_/\ * (= ._.) * / >0 \>1 **/
#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...