Skip to content

Commit

Permalink
Merge pull request #1055 from yosupo06/refactor/unionfind
Browse files Browse the repository at this point in the history
make unionfind to use param
  • Loading branch information
yosupo06 authored Nov 8, 2023
2 parents 99487e3 + bf9be23 commit 75e8e5e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
23 changes: 11 additions & 12 deletions datastructure/unionfind/gen/path.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#include "random.h"
#include "../params.h"
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <utility>
#include <vector>
#include <algorithm>

int main(int, char *argv[]) {
const long long seed = std::atoll(argv[1]);
Random gen(seed);

const int N = 200000;
const int Q = 200000;

assert(N == Q);
const int N_AND_Q = std::min(N_MAX, Q_MAX);

struct query_type {
int t;
int u;
int v;
};

std::vector<query_type> qs(Q);
std::vector<query_type> qs(N_AND_Q);

// unused-but-set-variable が誤反応するようなので、抑制する
#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER)
Expand All @@ -30,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;
Expand All @@ -46,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) {
Expand All @@ -69,10 +68,10 @@ int main(int, char *argv[]) {
#pragma GCC diagnostic pop
#endif

std::vector<int> p(N);
std::vector<int> 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]);
}
Expand Down
5 changes: 3 additions & 2 deletions datastructure/unionfind/gen/random.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <iostream>
#include "random.h"
#include "../params.h"

using namespace std;

Expand All @@ -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<int>(1, N_MAX);
int q = gen.uniform<int>(1, Q_MAX);
printf("%d %d\n", n, q);
for (int i = 0; i < q; i++) {
int ty = gen.uniform_bool();
Expand Down
4 changes: 4 additions & 0 deletions datastructure/unionfind/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions datastructure/unionfind/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 75e8e5e

Please sign in to comment.