Submission #546789

#TimeUsernameProblemLanguageResultExecution timeMemory
546789MonarchuwuDuathlon (APIO18_duathlon)C++17
0 / 100
24 ms1912 KiB
#include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int N = 1e5 + 9; int n, m; 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 calc(int n) { return (ll)n * (n - 1) * (n - 2) / 3; } 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); } ll ans(0); for (int i = 1; i <= n; ++i) if (par[i] < 0) ans += calc(-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...