From 172ba6cc713cc4899510e3259205c3c71bf4aba2 Mon Sep 17 00:00:00 2001 From: hitonanode <32937551+hitonanode@users.noreply.github.com> Date: Wed, 2 Oct 2024 23:55:49 +0900 Subject: [PATCH] WeightedUnionFind -> PotentializedUnionFind --- ...eighted_unionfind.hpp => potentialized_unionfind.hpp} | 7 +++---- ...{weighted_unionfind.md => potentialized_unionfind.md} | 9 +++++---- ...ionfind.test.cpp => potentialized_unionfind.test.cpp} | 4 ++-- ....cpp => potentialized_unionfind_F2.yuki1420.test.cpp} | 4 ++-- ....cpp => potentialized_unionfind_int.aoj3142.test.cpp} | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) rename unionfind/{weighted_unionfind.hpp => potentialized_unionfind.hpp} (85%) rename unionfind/{weighted_unionfind.md => potentialized_unionfind.md} (67%) rename unionfind/test/{weighted_unionfind.test.cpp => potentialized_unionfind.test.cpp} (87%) rename unionfind/test/{weighted_unionfind_F2.yuki1420.test.cpp => potentialized_unionfind_F2.yuki1420.test.cpp} (86%) rename unionfind/test/{weighted_unionfind_int.aoj3142.test.cpp => potentialized_unionfind_int.aoj3142.test.cpp} (89%) diff --git a/unionfind/weighted_unionfind.hpp b/unionfind/potentialized_unionfind.hpp similarity index 85% rename from unionfind/weighted_unionfind.hpp rename to unionfind/potentialized_unionfind.hpp index 478d4db9..3f39f083 100644 --- a/unionfind/weighted_unionfind.hpp +++ b/unionfind/potentialized_unionfind.hpp @@ -3,12 +3,11 @@ #include #include -// CUT begin -// Weighted UnionFind -template struct WeightedUnionFind { +// Potentialized UnionFind (Weighted UnionFind) +template struct PotentializedUnionFind { std::vector par, sz; std::vector pot; - WeightedUnionFind(int N = 0) : par(N), sz(N, 1), pot(N) { + PotentializedUnionFind(int N = 0) : par(N), sz(N, 1), pot(N) { std::iota(par.begin(), par.end(), 0); } int find(int x) { diff --git a/unionfind/weighted_unionfind.md b/unionfind/potentialized_unionfind.md similarity index 67% rename from unionfind/weighted_unionfind.md rename to unionfind/potentialized_unionfind.md index 3a52d416..59b03a84 100644 --- a/unionfind/weighted_unionfind.md +++ b/unionfind/potentialized_unionfind.md @@ -1,6 +1,6 @@ --- -title: Weighted UnionFind (重み付き UnionFind) -documentation_of: ./weighted_unionfind.hpp +title: Potentialized UnionFind (重み付き UnionFind) +documentation_of: ./potentialized_unionfind.hpp --- 2個の要素間の重みづけが可能な UnionFind. @@ -10,7 +10,7 @@ documentation_of: ./weighted_unionfind.hpp ポテンシャルが(ふつうの)整数の場合. ```cpp -WeightedUnionFind uf(N); +PotentializedUnionFind uf(N); uf.unite(s, t, diff); // f[t] = f[s] + diff を要請.これまでの要請と矛盾すれば false を返す. auto x = uf.diff(s, t); // f[t] - f[s] (として考えられる値の一つ)を出力. @@ -19,9 +19,10 @@ auto x = uf.diff(s, t); // f[t] - f[s] (として考えられる値の一つ ポテンシャルが $\mathbb{F}_{2}$ 上のベクトルの場合. ```cpp -WeightedUnionFind uf(N); +PotentializedUnionFind uf(N); ``` ## 問題例 - [No.1420 国勢調査 (Easy) - yukicoder](https://yukicoder.me/problems/no/1420) $\mathbb{F}_2$ 上のベクトル. +- [AtCoder Beginner Contest 373 D - Hidden Weights](https://atcoder.jp/contests/abc373/tasks/abc373_d) diff --git a/unionfind/test/weighted_unionfind.test.cpp b/unionfind/test/potentialized_unionfind.test.cpp similarity index 87% rename from unionfind/test/weighted_unionfind.test.cpp rename to unionfind/test/potentialized_unionfind.test.cpp index 198c49c2..9b3da0cf 100644 --- a/unionfind/test/weighted_unionfind.test.cpp +++ b/unionfind/test/potentialized_unionfind.test.cpp @@ -1,4 +1,4 @@ -#include "../weighted_unionfind.hpp" +#include "../potentialized_unionfind.hpp" #include #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_B&lang=jp" using namespace std; @@ -6,7 +6,7 @@ using namespace std; int main() { int N, Q, x, y, z; cin >> N >> Q; - WeightedUnionFind uf(N); + PotentializedUnionFind uf(N); for (int i = 0; i < Q; i++) { int c; cin >> c; diff --git a/unionfind/test/weighted_unionfind_F2.yuki1420.test.cpp b/unionfind/test/potentialized_unionfind_F2.yuki1420.test.cpp similarity index 86% rename from unionfind/test/weighted_unionfind_F2.yuki1420.test.cpp rename to unionfind/test/potentialized_unionfind_F2.yuki1420.test.cpp index 39c04cfa..16c74c80 100644 --- a/unionfind/test/weighted_unionfind_F2.yuki1420.test.cpp +++ b/unionfind/test/potentialized_unionfind_F2.yuki1420.test.cpp @@ -1,7 +1,7 @@ #define PROBLEM "https://yukicoder.me/problems/no/1420" #define ERROR 1 // Check only whether the answer is -1 or not #include "../../number/nimber.hpp" -#include "../weighted_unionfind.hpp" +#include "../potentialized_unionfind.hpp" #include using namespace std; @@ -10,7 +10,7 @@ int main() { int N, M; cin >> N >> M; - WeightedUnionFind uf(N); + PotentializedUnionFind uf(N); while (M--) { int a, b, y; cin >> a >> b >> y; diff --git a/unionfind/test/weighted_unionfind_int.aoj3142.test.cpp b/unionfind/test/potentialized_unionfind_int.aoj3142.test.cpp similarity index 89% rename from unionfind/test/weighted_unionfind_int.aoj3142.test.cpp rename to unionfind/test/potentialized_unionfind_int.aoj3142.test.cpp index 0cbb60da..de012b3f 100644 --- a/unionfind/test/weighted_unionfind_int.aoj3142.test.cpp +++ b/unionfind/test/potentialized_unionfind_int.aoj3142.test.cpp @@ -1,5 +1,5 @@ #define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3142" -#include "../weighted_unionfind.hpp" +#include "../potentialized_unionfind.hpp" #include #include #include @@ -8,7 +8,7 @@ using namespace std; int N; vector> to; vector A, B; -WeightedUnionFind uf; +PotentializedUnionFind uf; long long dfs(int now, int prv) { long long acc = B[now] - A[now]; @@ -26,7 +26,7 @@ int main() { cin.tie(nullptr), ios::sync_with_stdio(false); cin >> N; - uf = WeightedUnionFind(N); + uf = PotentializedUnionFind(N); to.resize(N); for (int e = 0; e < N - 1; e++) {