| 130 | }; |
| 131 | |
| 132 | void test() { |
| 133 | int tests = 100; |
| 134 | |
| 135 | for (int t = 0; t < tests; t++) { |
| 136 | int n = rng() % 10000 + 1; |
| 137 | int q = rng() % 10000 + 1; |
| 138 | |
| 139 | pair<vi*, int> xadj = random_tree(n); |
| 140 | vi *adj = xadj.first; |
| 141 | int root = xadj.second; |
| 142 | |
| 143 | int *ps = pars(n, adj); |
| 144 | |
| 145 | lca_tree tr(n, root, adj); |
| 146 | tarjan_olca lca(n, adj); |
| 147 | |
| 148 | vii qs; |
| 149 | for (int i = 0; i < q; i++) { |
| 150 | int a = rng() % n, |
| 151 | b = rng() % n; |
| 152 | |
| 153 | qs.push_back(ii(a, b)); |
| 154 | lca.query(a, b); |
| 155 | } |
| 156 | |
| 157 | lca.process(root); |
| 158 | |
| 159 | for (int i = 0; i < q; i++) { |
| 160 | int correct = lca_slow(n, ps, qs[i].first, qs[i].second); |
| 161 | int maybe = lca.answers[i]; |
| 162 | int maybe2 = tr.lca(qs[i].first, qs[i].second); |
| 163 | assert_equal(correct, maybe); |
| 164 | assert_equal(correct, maybe2); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | } |
| 169 | // vim: cc=60 ts=2 sts=2 sw=2: |
nothing calls this directly
no test coverage detected