diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-11-16 01:24:14 +0100 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-11-16 01:24:14 +0100 |
| commit | 98567ec798aa8ca2cfbcb85c774dd470f30e30d4 (patch) | |
| tree | 5113d5cc24d1ad5f93810b6442ce584a36950dc8 /graph/test/LCA_sparse.cpp | |
| parent | ad3856a6b766087df0036de0b556f4700a6498c9 (diff) | |
| parent | 8d11c6c8213f46f0fa19826917c255edd5d43cb1 (diff) | |
mzuenni tests
Diffstat (limited to 'graph/test/LCA_sparse.cpp')
| -rw-r--r-- | graph/test/LCA_sparse.cpp | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/graph/test/LCA_sparse.cpp b/graph/test/LCA_sparse.cpp deleted file mode 100644 index c8b0017..0000000 --- a/graph/test/LCA_sparse.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "util.cpp" -#define all(X) begin(X), end(X) -#define sz ssize -#include "../../datastructures/sparseTable.cpp" -#include "../LCA_sparse.cpp" - -void test(vector<vector<int>> &adj, int root) { - int n = adj.size(); - - vector<int> parent(n); - function<void(int,int)> dfs = [&](int u, int p) { - parent[u] = p; - for (int v: adj[u]) if (v != p) dfs(v, u); - }; - dfs(root, -1); - - function<bool(int, int)> is_ancestor = [&](int u, int v) { - while (v != -1 && u != v) v = parent[v]; - return u == v; - }; - function<int(int)> depth = [&](int v) { - int r = 0; - while ((v = parent[v]) != -1) r++; - return r; - }; - - LCA lca; - lca.init(adj, root); - for (int i = 0; i < n; i++) assert(lca.getDepth(i) == depth(i)); - for (int i = 0; i < 1000; i++) { - int u = util::randint(n); - int v = util::randint(n); - int l = lca.getLCA(u, v); - assert(is_ancestor(l, u)); - assert(is_ancestor(l, v)); - for (int p = parent[l]; int c: adj[l]) { - if (c == p) continue; - assert(!is_ancestor(c, u) || !is_ancestor(c, v)); - } - } -} - -int main() { - { - // Single vertex - vector<vector<int>> adj(1); - test(adj, 0); - } - { - // Path - vector<vector<int>> adj = util::path(100); - int left = 0, mid = 40, right = 99; - util::shuffle_graph(adj, left, mid, right); - test(adj, left); - test(adj, mid); - test(adj, right); - } - { - // Random - vector<vector<int>> adj = util::random_tree(1000); - test(adj, 0); - } -} |
