File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed
library/data_structures/dsu
tests/library_checker_aizu_tests/graphs Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 11#pragma once
22// NOLINTNEXTLINE(readability-identifier-naming)
33struct DSU {
4- vi e ;
5- DSU (int n): e (n, -1 ) {}
6- int size (int x) { return -e [go (x)]; }
7- int go (int x) { return e [x] < 0 ? x : e [x] = go (e [x]); }
4+ vi p ;
5+ DSU (int n): p (n, -1 ) {}
6+ int size (int x) { return -p [go (x)]; }
7+ int go (int x) { return p [x] < 0 ? x : p [x] = go (p [x]); }
88 bool join (int a, int b) {
99 if ((a = go (a)) == (b = go (b))) return 0 ;
10- if (e [a] > e [b]) swap (a, b);
11- return e [a] += e [b], e [b] = a, 1 ;
10+ if (p [a] > p [b]) swap (a, b);
11+ return p [a] += p [b], p [b] = a, 1 ;
1212 }
1313};
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ int main() {
2727 auto [u, v] = eds[order[it]];
2828 u = dsu.go (u);
2929 v = dsu.go (v);
30- if (dsu.e [u] > dsu.e [v]) swap (u, v);
30+ if (dsu.p [u] > dsu.p [v]) swap (u, v);
3131 if (u != v) {
3232 sum = (sum + 1LL * xs[u] * xs[v]) % mod;
3333 xs[u] = (xs[u] + xs[v]) % mod;
You can’t perform that action at this time.
0 commit comments