From 751812a2a95a9b6266dcf2eb91f0bbc56b865e4d Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Thu, 9 Nov 2023 01:11:28 +0900 Subject: [PATCH 1/2] make unionfind to use param --- datastructure/unionfind/gen/path.cpp | 5 +++-- datastructure/unionfind/gen/random.cpp | 5 +++-- datastructure/unionfind/info.toml | 4 ++++ datastructure/unionfind/task.md | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/datastructure/unionfind/gen/path.cpp b/datastructure/unionfind/gen/path.cpp index 579fbd1a0..bd380e3ca 100644 --- a/datastructure/unionfind/gen/path.cpp +++ b/datastructure/unionfind/gen/path.cpp @@ -1,4 +1,5 @@ #include "random.h" +#include "../params.h" #include #include #include @@ -10,8 +11,8 @@ int main(int, char *argv[]) { const long long seed = std::atoll(argv[1]); Random gen(seed); - const int N = 200000; - const int Q = 200000; + const int N = N_MAX; + const int Q = Q_MAX; assert(N == Q); diff --git a/datastructure/unionfind/gen/random.cpp b/datastructure/unionfind/gen/random.cpp index 139236d81..2f54c11f7 100644 --- a/datastructure/unionfind/gen/random.cpp +++ b/datastructure/unionfind/gen/random.cpp @@ -1,5 +1,6 @@ #include #include "random.h" +#include "../params.h" using namespace std; @@ -8,8 +9,8 @@ int main(int, char* argv[]) { long long seed = atoll(argv[1]); auto gen = Random(seed); - int n = gen.uniform(1, 200000); - int q = gen.uniform(1, 200000); + int n = gen.uniform(1, N_MAX); + int q = gen.uniform(1, Q_MAX); printf("%d %d\n", n, q); for (int i = 0; i < q; i++) { int ty = gen.uniform_bool(); diff --git a/datastructure/unionfind/info.toml b/datastructure/unionfind/info.toml index eec44b8ae..60602aaab 100644 --- a/datastructure/unionfind/info.toml +++ b/datastructure/unionfind/info.toml @@ -11,3 +11,7 @@ forum = 'https://github.com/yosupo06/library-checker-problems/issues/33' [[tests]] name = "path.cpp" number = 4 + +[params] + N_MAX = 200_000 + Q_MAX = 200_000 diff --git a/datastructure/unionfind/task.md b/datastructure/unionfind/task.md index c6231c7de..a44392bbb 100644 --- a/datastructure/unionfind/task.md +++ b/datastructure/unionfind/task.md @@ -16,8 +16,8 @@ $N$ 頂点 $0$ 辺の無向グラフに $Q$ 個のクエリが飛んできます ## @{keyword.constraints} -- $1 \leq N \leq 200,000$ -- $1 \leq Q \leq 200,000$ +- $1 \leq N \leq @{param.N_MAX}$ +- $1 \leq Q \leq @{param.Q_MAX}$ - $0 \leq u_i, v_i \lt N$ ## @{keyword.input} From bf9be234014f22eda47ff564faa1a433ca43aa0d Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Thu, 9 Nov 2023 01:22:40 +0900 Subject: [PATCH 2/2] fix by review --- datastructure/unionfind/gen/path.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/datastructure/unionfind/gen/path.cpp b/datastructure/unionfind/gen/path.cpp index bd380e3ca..ae0a98324 100644 --- a/datastructure/unionfind/gen/path.cpp +++ b/datastructure/unionfind/gen/path.cpp @@ -6,15 +6,13 @@ #include #include #include +#include int main(int, char *argv[]) { const long long seed = std::atoll(argv[1]); Random gen(seed); - const int N = N_MAX; - const int Q = Q_MAX; - - assert(N == Q); + const int N_AND_Q = std::min(N_MAX, Q_MAX); struct query_type { int t; @@ -22,7 +20,7 @@ int main(int, char *argv[]) { int v; }; - std::vector qs(Q); + std::vector qs(N_AND_Q); // unused-but-set-variable が誤反応するようなので、抑制する #if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) @@ -31,14 +29,14 @@ int main(int, char *argv[]) { #endif if (seed == 0 || seed == 1) { // parent[v] = u 最悪ケース - const int K = 2 * N / 3; + const int K = 2 * N_AND_Q / 3; for (int i = 0; i != K; i += 1) { auto &[t, u, v] = qs[i]; t = 0; u = i + 1; v = 0; } - for (int i = K; i != Q; i += 1) { + for (int i = K; i != N_AND_Q; i += 1) { auto &[t, u, v] = qs[i]; t = 1; u = 0; @@ -47,17 +45,17 @@ int main(int, char *argv[]) { } if (seed == 2 || seed == 3) { // parent[v] = u 深さ最大 - for (int i = 0; i != Q - 1; i += 1) { + for (int i = 0; i != N_AND_Q - 1; i += 1) { auto &[t, u, v] = qs[i]; t = 0; u = i + 1; v = i; } { - auto &[t, u, v] = qs[Q - 1]; + auto &[t, u, v] = qs[N_AND_Q - 1]; t = 0; u = 0; - v = Q - 1; + v = N_AND_Q - 1; } } if (seed == 1 || seed == 3) { @@ -70,10 +68,10 @@ int main(int, char *argv[]) { #pragma GCC diagnostic pop #endif - std::vector p(N); + std::vector p(N_AND_Q); std::iota(p.begin(), p.end(), 0); gen.shuffle(p.begin(), p.end()); - std::printf("%d %d\n", N, Q); + std::printf("%d %d\n", N_AND_Q, N_AND_Q); for (const auto &[t, u, v] : qs) { std::printf("%d %d %d\n", t, p[u], p[v]); }