Skip to content

Commit

Permalink
Merge pull request yosupo06#1247 from maspypy/1233
Browse files Browse the repository at this point in the history
テストケース追加(1233)
  • Loading branch information
maspypy authored Nov 11, 2024
2 parents 6d26f5f + e46ec36 commit 5a74e3f
Show file tree
Hide file tree
Showing 8 changed files with 485 additions and 6 deletions.
45 changes: 43 additions & 2 deletions tree/point_set_tree_path_composite_sum/gen/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ struct QueryData {
int N, Q;
vector<int> cmd, I, X, Y, R;

QueryData(int _n, int _q, Random& gen)
: N(_n), Q(_q), cmd(Q), I(Q), X(Q), Y(Q, -1), R(Q) {
QueryData(int _n, int _q, Random& gen) : N(_n), Q(_q), cmd(Q), I(Q), X(Q), Y(Q, -1), R(Q) {
for (int i = 0; i < Q; i++) {
cmd[i] = gen.uniform(0, 1);
if (N == 1) cmd[i] = 0;
Expand All @@ -40,3 +39,45 @@ struct QueryData {
}
}
};

struct QueryData_degree {
int N, Q;
vector<int> cmd, I, X, Y, R;

QueryData_degree(int _n, int _q, Random& gen, vector<int> deg) : N(_n), Q(_q), cmd(Q), I(Q), X(Q), Y(Q, -1), R(Q) {
vector<int> S;
for (int i = 0; i < N; ++i) {
for (int cnt = 0; cnt < deg[i]; ++cnt) S.emplace_back(i);
}
if (S.empty()) S.emplace_back(0);
auto random_S = [&]() -> int {
int idx = gen.uniform(0, int(S.size()) - 1);
return S[idx];
};

for (int i = 0; i < Q; i++) {
cmd[i] = gen.uniform(0, 1);
if (N == 1) cmd[i] = 0;
if (cmd[i] == 0) {
I[i] = random_S();
X[i] = gen.uniform(A_MIN, MOD - 1);
R[i] = random_S();
} else {
I[i] = gen.uniform(0, N - 2);
X[i] = gen.uniform(B_MIN, MOD - 1);
Y[i] = gen.uniform(C_MIN, MOD - 1);
R[i] = random_S();
}
}
}

void print() {
for (int i = 0; i < Q; i++) {
if (cmd[i] == 0) {
printf("%d %d %d %d\n", cmd[i], I[i], X[i], R[i]);
} else {
printf("%d %d %d %d %d\n", cmd[i], I[i], X[i], Y[i], R[i]);
}
}
}
};
177 changes: 177 additions & 0 deletions tree/point_set_tree_path_composite_sum/gen/typical_tree_max_degree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@

#include <algorithm>
#include <cassert>
#include <utility>
#include <vector>

#include "../params.h"
#include "query.h"
#include "random.h"

struct Tree {
int n = 1;
std::vector<std::pair<int, int>> edges;

void shuffle_nodes(Random& rng) {
auto perm = rng.perm<int>(n);
for (auto& e: edges) {
e.first = perm[e.first];
e.second = perm[e.second];
}
}
void shuffle_edges(Random& rng, bool can_flip = true) {
rng.shuffle(edges.begin(), edges.end());
if (can_flip) {
for (auto& e: edges) {
if (rng.uniform_bool()) std::swap(e.first, e.second);
}
}
}

void push(int u, int v) { edges.emplace_back(u, v); }

void expand_random_edges(Random& rng, int count) {
assert(n >= 2);
int fixn = n;
for (int i = 0; i < count; i++) {
int e = rng.uniform(0, fixn - 2);
push(edges[e].first, n);
edges[e].first = n;
n++;
}
}

void join_random_edges(Random& rng, int count) {
int fixn = n;
for (int i = 0; i < count; i++) {
push(rng.uniform(0, fixn - 1), n);
n++;
}
}

void toCentipede() {
int fixn = n;
for (int i = 0; i < fixn; i++) {
push(i, n);
n++;
}
}

static Tree Line(int n) {
Tree res;
res.n = n;
for (int i = 0; i < n - 1; i++) res.push(i, i + 1);
return res;
}

static Tree Star(int n) {
Tree res;
res.n = n;
for (int i = 0; i < n - 1; i++) res.push(0, i + 1);
return res;
}

static Tree KLines(int n, int k) {
assert(3 <= k);
Tree res;
res.n = n;
for (int i = 1; i < n; i++) res.push(std::max(0, i - k), i);
return res;
}

static Tree KAry(int n, int k) {
assert(2 <= k);
Tree res;
res.n = n;
for (int i = 0; i < n - 1; i++) res.push(i / k, i + 1);
return res;
}

static Tree Broom(int n, int line_length) {
assert(line_length <= n);
Tree res;
res.n = n;
for (int i = 0; i < line_length; i++) res.push(i, i + 1);
for (int i = line_length; i < n - 1; i++) res.push(line_length - 1, i + 1);
return res;
}

static Tree LongestPathDecompositionKiller(int n) {
assert(n >= 10);
Tree res;
res.n = n;
std::vector<int> rt;
int now_n = 0;
for (int len = 1;; len += 2) {
if (now_n + len > n) break;
for (int i = 0; i < len - 1; i++) { res.push(now_n + i, now_n + i + 1); }
rt.push_back(now_n);
now_n += len;
}
for (int i = 0; i + 1 < (int)rt.size(); i++) { res.push(rt[i], rt[i + 1]); }
for (int i = now_n; i < n; i++) { res.push(i - 1, i); }
return res;
}

static Tree GenerateByTemplateId(Random& rng, int id, int n) {
assert(n >= 10);
assert(id >= 0);
if (id-- == 0) return Line(n);
if (id-- == 0) return Star(n);
if (id-- == 0) return KAry(n, 2);
if (id-- == 0) return LongestPathDecompositionKiller(n);
if (id-- == 0) {
auto res = Line(n / 2);
res.toCentipede();
res.join_random_edges(rng, n % 2);
return res;
}
if (id-- == 0) return Broom(n, (long long)n * 2 / 5);
if (id-- == 0) return Broom(n, (long long)n * 3 / 5);
if (id-- == 0) return KLines(n, 3);
if (id-- == 0) return KAry(n, 3);
if (id-- == 0) {
auto res = Star(n / 2);
res.expand_random_edges(rng, n / 2);
return res;
}
assert(false);
}
};

int main(int, char* argv[]) {
int id = (int)atoll(argv[1]);
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int N = N_MAX;
int Q = Q_MAX;

Tree tree = Tree::GenerateByTemplateId(gen, id, N);
tree.shuffle_edges(gen);
tree.shuffle_nodes(gen);

std::vector<int> A(N), B(N - 1), C(N - 1);
for (int i = 0; i < N; i++) A[i] = gen.uniform(A_MIN, MOD - 1);
for (int i = 0; i < N - 1; i++) B[i] = gen.uniform(B_MIN, MOD - 1);
for (int i = 0; i < N - 1; i++) C[i] = gen.uniform(C_MIN, MOD - 1);

printf("%d %d\n", N, Q);

for (int i = 0; i < N; i++) {
if (i) printf(" ");
printf("%d", A[i]);
}
printf("\n");

vector<int> deg(N);

for (int i = 0; i < N - 1; i++) {
printf("%d %d %d %d\n", tree.edges[i].first, tree.edges[i].second, B[i], C[i]);
deg[tree.edges[i].first]++, deg[tree.edges[i].second]++;
}

QueryData_degree qd{N, Q, gen, deg};
qd.print();
return 0;
}
22 changes: 21 additions & 1 deletion tree/point_set_tree_path_composite_sum/hash.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,25 @@
"typical_tree_max_08.in": "b3836b3b2ac7cea93e18b7bbe776e50fe9d758e8be80626b08bbf692ea4b9a8b",
"typical_tree_max_08.out": "53626225161187fa26a650c1f5a2e1453c050cb4e165a77fa9269f7a3be92e1f",
"typical_tree_max_09.in": "030edc92a2fba1e566740cd2e34eb84651d13da4c562a9bf292507a5692657f6",
"typical_tree_max_09.out": "4f62c9600672121ca33a1223baef50a711e1eb75788b85525280d0aa6c6fdf39"
"typical_tree_max_09.out": "4f62c9600672121ca33a1223baef50a711e1eb75788b85525280d0aa6c6fdf39",
"typical_tree_max_degree_00.in": "d5f398524a11778031340ca2aad452da7b7b241167c523d5c31fd638c8ea8931",
"typical_tree_max_degree_00.out": "6c6d1cbe1229e24b5c9d731f909e877700abe27d8eb4c8310ce0de8d48de229e",
"typical_tree_max_degree_01.in": "1696ba8a50219381752b36de5a93c299e93dc0c35baa8701a7c7b5cf06692093",
"typical_tree_max_degree_01.out": "d6d76f403d2f89f0258e4ac24055282833d8a8bde272221a1d12139dc31b33fa",
"typical_tree_max_degree_02.in": "87c4bf0b434951621ee8f8cfa84ecb5da825e228a4c5c1f58856737cfd68617d",
"typical_tree_max_degree_02.out": "3e26c37d7c9501acc7e9df35f3d4570324e101bd27779dfe258773619e7707c2",
"typical_tree_max_degree_03.in": "b8811f61945eb7416e99bd5cd0dbf0c1ceea4805e9082d1ffe637c11a4c6a9f9",
"typical_tree_max_degree_03.out": "6390a58a17f225d436098f055350abe910099a0f686b637a6eb4d378a538c570",
"typical_tree_max_degree_04.in": "d8f4658d976bc8ed4c31e40db126c74d0feacc6167ba89914d4c041452f724d1",
"typical_tree_max_degree_04.out": "e5a9208537ddb313b12ad3d22c8b91416cec0c54b8d34ff461aa4176cd7b56a0",
"typical_tree_max_degree_05.in": "ddb79d54e85c3615d1ec8607ae8784c949d8b80255f0a58fb425e309427ac563",
"typical_tree_max_degree_05.out": "4a73f0501333d8ac402b078521f21e97fc832aa3c824104e26ce3aeb9b2cf836",
"typical_tree_max_degree_06.in": "475e3aa8fb14ab7ec7a0897b10da0b19a887a10bf7ec8191c5852043d3575847",
"typical_tree_max_degree_06.out": "2dd2fe91fe8e6236339cb455b2291d6823961ff34adf27917712dbd0783668cb",
"typical_tree_max_degree_07.in": "e34caaaf981870421a58c3c4cb27f5dc0f86c13db6695cc1320b989e824e7a02",
"typical_tree_max_degree_07.out": "e94e2df60e725c8867ed1a16b6a92f9004eddf4872e8a2495cd2ed63ab3e89fb",
"typical_tree_max_degree_08.in": "d26f3ea477319aa2c5c0bda0bb48b28fd3671c52d8c86a53a3a5343c1e398a4c",
"typical_tree_max_degree_08.out": "2894000ea382d7b073d4fb6796149627b59497b6c809a110cbc6ebac40a63a2a",
"typical_tree_max_degree_09.in": "339f20acaf869b992dd161950233e2a4a107909844c355c45beda7b725cab96e",
"typical_tree_max_degree_09.out": "c6a37a2bb30f16fc37d722d73fe75f3ab90514f90d4412ebe7232ca0a1b14729"
}
3 changes: 3 additions & 0 deletions tree/point_set_tree_path_composite_sum/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/1142"
[[tests]]
name = "typical_tree_max.cpp"
number = 10
[[tests]]
name = "typical_tree_max_degree.cpp"
number = 10

[[solutions]]
name = "naive.cpp"
Expand Down
43 changes: 41 additions & 2 deletions tree/point_set_tree_path_composite_sum_fixed_root/gen/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ struct QueryData {
int N, Q;
vector<int> cmd, I, X, Y;

QueryData(int _n, int _q, Random& gen)
: N(_n), Q(_q), cmd(Q), I(Q), X(Q), Y(Q, -1) {
QueryData(int _n, int _q, Random& gen) : N(_n), Q(_q), cmd(Q), I(Q), X(Q), Y(Q, -1) {
for (int i = 0; i < Q; i++) {
cmd[i] = gen.uniform(0, 1);
if (N == 1) cmd[i] = 0;
Expand All @@ -38,3 +37,43 @@ struct QueryData {
}
}
};

struct QueryData_degree {
int N, Q;
vector<int> cmd, I, X, Y;

QueryData_degree(int _n, int _q, Random& gen, vector<int> deg) : N(_n), Q(_q), cmd(Q), I(Q), X(Q), Y(Q, -1) {
vector<int> S;
for (int i = 0; i < N; ++i) {
for (int cnt = 0; cnt < deg[i]; ++cnt) S.emplace_back(i);
}
if (S.empty()) S.emplace_back(0);
auto random_S = [&]() -> int {
int idx = gen.uniform(0, int(S.size()) - 1);
return S[idx];
};

for (int i = 0; i < Q; i++) {
cmd[i] = gen.uniform(0, 1);
if (N == 1) cmd[i] = 0;
if (cmd[i] == 0) {
I[i] = random_S();
X[i] = gen.uniform(A_MIN, MOD - 1);
} else {
I[i] = gen.uniform(0, N - 2);
X[i] = gen.uniform(B_MIN, MOD - 1);
Y[i] = gen.uniform(C_MIN, MOD - 1);
}
}
}

void print() {
for (int i = 0; i < Q; i++) {
if (cmd[i] == 0) {
printf("%d %d %d\n", cmd[i], I[i], X[i]);
} else {
printf("%d %d %d %d\n", cmd[i], I[i], X[i], Y[i]);
}
}
}
};
Loading

0 comments on commit 5a74e3f

Please sign in to comment.