Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

テストケース追加 #1257

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions tree/lca/gen/almost_line.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <iostream>
#include <queue>
#include "../params.h"
#include "random.h"

using namespace std;

// vertex add path sum からもってきたもの
int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);

int n = N_MAX;
int q = Q_MAX;
printf("%d %d\n", n, q);

// parent の列が必要
vector<int> par(n, -1);
for (int i = 0; i < n - (n / 2); i++) {
// u[i] = i;
// v[i] = i + 1;
par[i + 1] = i;
}
for (int i = n - (n / 2); i < n - 1; i++) {
// u[i] = gen.uniform(0, i);
// v[i] = i + 1;
par[i + 1] = gen.uniform(0, i);
}
// 頂点ラベルをシャッフルしたいが, p[i]<i にする必要がある
// ランダム優先順位でトポロジカル順序をとる
priority_queue<pair<int, int>> que;
auto add_que = [&](int v) -> void {
int pri = gen.uniform<int>(0, 1'000'000'000);
que.emplace(pri, v);
};
add_que(0);

vector<vector<int>> ch(n);
for (int i = 1; i < n; ++i) ch[par[i]].emplace_back(i);

vector<int> new_idx(n);
for (int i = 0; i < n; ++i) {
int v = que.top().second;
que.pop();
new_idx[v] = i;
for (auto& w: ch[v]) add_que(w);
}

vector<int> tmp(n, -1);
for (int i = 1; i < n; ++i) { tmp[new_idx[i]] = new_idx[par[i]]; }
swap(par, tmp);

for (int i = 1; i < n; ++i) {
if (i > 1) printf(" ");
printf("%d", par[i]);
}
printf("\n");

for (int i = 0; i < q; i++) {
auto [u, v] = gen.uniform_pair<int>(0, n - 1);
printf("%d %d\n", u, v);
}
return 0;
}
4 changes: 4 additions & 0 deletions tree/lca/hash.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"almost_line_00.in": "ea3f1411571fa29bbaaa70c407c19168382c40a1ea4189823dcd394ed155fd1b",
"almost_line_00.out": "bfff4a3ba6228102152ba4c039b139f42b65a78ba15d2c50e2507f565b36eda1",
"almost_line_01.in": "8d8360a96a0e1ffefa8c7ed04b09c86c24ffa3d181d29862128bcb45b23420e1",
"almost_line_01.out": "4cbd1c40f987819aa0ef69ba778deede4471d30f935eac5af5d4f6ba78cd0b84",
"binary_00.in": "6e7c16bc8af7a039b1ac60ce46b085b7950381faf413d4006f6e668ca229707a",
"binary_00.out": "dd71c4b7b1c5dde2bade5e3510230c71b894200f39431c60e6b69454b4ec5155",
"binary_01.in": "20d7fb5dd98dbef4ba16e080dd80b1b729d9c0044231f2baeb4aaa6c540c41e6",
Expand Down
4 changes: 4 additions & 0 deletions tree/lca/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/35"
name = "path_graph_root_centroid.cpp"
number = 3

[[tests]]
name = "almost_line.cpp"
number = 2

[[solutions]]
name = "tle.cpp"
expect = "TLE"
Expand Down