Skip to content

Commit

Permalink
Merge pull request #1143 from NyaanNyaan/master
Browse files Browse the repository at this point in the history
add point_set_tree_path_composite_sum
  • Loading branch information
maspypy authored Apr 29, 2024
2 parents 8df65e6 + 2b9f3e3 commit 9c6db3e
Show file tree
Hide file tree
Showing 18 changed files with 2,235 additions and 0 deletions.
62 changes: 62 additions & 0 deletions graph/point_set_tree_path_composite_sum/checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// https://github.com/MikeMirzayanov/testlib/blob/master/checkers/wcmp.cpp

// The MIT License (MIT)

// Copyright (c) 2015 Mike Mirzayanov

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "testlib.h"

using namespace std;

int main(int argc, char * argv[])
{
setName("compare sequences of tokens");
registerTestlibCmd(argc, argv);

int n = 0;
string j, p;

while (!ans.seekEof() && !ouf.seekEof())
{
n++;

ans.readWordTo(j);
ouf.readWordTo(p);

if (j != p)
quitf(_wa, "%d%s words differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), compress(j).c_str(), compress(p).c_str());
}

if (ans.seekEof() && ouf.seekEof())
{
if (n == 1)
quitf(_ok, "\"%s\"", compress(j).c_str());
else
quitf(_ok, "%d tokens", n);
}
else
{
if (ans.seekEof())
quitf(_wa, "Participant output contains extra tokens");
else
quitf(_wa, "Unexpected EOF in the participants output");
}
}
6 changes: 6 additions & 0 deletions graph/point_set_tree_path_composite_sum/gen/example_00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
3 2
1 2 3
0 1 4 5
1 2 6 7
0 2 8 0
1 0 9 10 1
13 changes: 13 additions & 0 deletions graph/point_set_tree_path_composite_sum/gen/example_01.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
8 4
1 2 3 4 5 6 7 8
0 1 10 1
1 2 10 1
0 3 10 1
0 4 10 0
0 5 10 1
5 6 10 0
6 7 10 1
0 6 10 5
1 4 100000 2 2
0 7 100000 3
0 0 100000 0
79 changes: 79 additions & 0 deletions graph/point_set_tree_path_composite_sum/gen/n_hundreds.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

#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 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++;
}
}
};

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

int N = gen.uniform(100, 300);
int Q = gen.uniform(100, 300);

Tree tree;
while (tree.n < N) {
tree.join_random_edges(gen, 1);
}

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");

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]);
}

QueryData qd{N, Q, gen};
qd.print();

return 0;
}
42 changes: 42 additions & 0 deletions graph/point_set_tree_path_composite_sum/gen/query.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// generate queries randomly

#include <cstdio>
#include <vector>

using namespace std;

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

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) {
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] = gen.uniform(0, N - 1);
X[i] = gen.uniform(A_MIN, MOD - 1);
R[i] = gen.uniform(0, N - 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);
R[i] = gen.uniform(0, N - 1);
}
}
}

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]);
}
}
}
};
4 changes: 4 additions & 0 deletions graph/point_set_tree_path_composite_sum/gen/tiny_00.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 2
1
0 0 2 0
0 0 3 0
12 changes: 12 additions & 0 deletions graph/point_set_tree_path_composite_sum/gen/tiny_01.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
2 9
1 100000
0 1 3 10
0 0 11 0
0 1 12 1
1 0 13 14 0
0 0 15 1
0 1 16 0
1 0 17 18 1
0 0 19 0
0 1 20 1
1 0 21 22 0
Loading

0 comments on commit 9c6db3e

Please sign in to comment.