aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2020-09-06 10:59:36 -0500
committerAnthony Wang2020-09-06 10:59:36 -0500
commitdcb2b2d3768f6467e68d285b48525ece51fd13ac (patch)
tree1a8768dfcb87985d3cb9a4b80e20fe95e785532d
parentfc0be861435ff31084adc65e2070d86ae802de08 (diff)
Fixed a few things in lca.cpp
-rw-r--r--Graph/lca.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/Graph/lca.cpp b/Graph/lca.cpp
index 2dcd05b..bba90aa 100644
--- a/Graph/lca.cpp
+++ b/Graph/lca.cpp
@@ -7,12 +7,12 @@ namespace lca {
}
int lca(vector<int> * G, int u, int v) {
if (d[u] > d[v]) swap(u, v);
- for (int i = 18; i >= 0; i--) if (d[v] - (1 << i) >= d[u]) v = L[v][i];
+ for (int i = 18; i >= 0; --i) if (d[v] - (1 << i) >= d[u]) v = L[v][i];
if (u == v) return u;
- for (int i = 18; i >= 0; i--) if (L[u][i] && L[u][i] != L[v][i]) u = L[u][i], v = L[v][i];
+ for (int i = 18; i >= 0; --i) if (L[u][i] && L[u][i] != L[v][i]) u = L[u][i], v = L[v][i];
return L[u][0];
}
inline int dist(vector<int> * G, int u, int v) {
- return d[u]+d[v]-2*lca(G, u, v);
+ return d[u]+d[v]-2*d[lca(G, u, v)];
}
}