MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / lca_slow

Function lca_slow

code/graph/tarjan_olca.test.cpp:4–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include "../code/data-structures/segment_tree.cpp"
3
4int lca_slow(int n, int *ps, int a, int b) {
5 vi as, bs;
6 while (a != -1) {
7 as.push_back(a);
8 a = ps[a];
9 }
10
11 while (b != -1) {
12 bs.push_back(b);
13 b = ps[b];
14 }
15
16 reverse(as.begin(), as.end());
17 reverse(bs.begin(), bs.end());
18
19 int at = 0;
20 while (at+1 < size(as) && at+1 < size(bs) && as[at+1] == bs[at+1]) {
21 at++;
22 }
23
24 return as[at];
25}
26
27int* pars(int n, vi *adj) {
28 int *res = new int[n];

Callers 1

testFunction · 0.85

Calls 1

push_backMethod · 0.80

Tested by

no test coverage detected