Skip to content
Snippets Groups Projects
Commit be5335d4 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Small fix lca

parent 692d9168
Branches
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ void dfs(int v, int p = -1, int c = 0) {
if (p + 1)
h[v] = h[p] + 1;
for (int i = 1; i < MAXLOG; i++)
for (int i = 1; i < MAXLOG; ++i)
if (par[v][i - 1] + 1) {
par[v][i] = par[par[v][i - 1]][i - 1];
//* cost[v][i] += cost[v][i - 1] + cost[par[v][i - 1]][i - 1];
......@@ -36,7 +36,7 @@ void dfs(int v, int p = -1, int c = 0) {
dfs(u.fi, v, u.se);
}
// Preprocess tree with rooted at v
// Preprocess tree rooted at v
void preprocess(int v) {
memset(par, -1, sizeof par);
memset(cost, 0, sizeof cost);
......@@ -50,7 +50,7 @@ int query(int p, int q) {
if (h[p] < h[q])
swap(p, q);
for (int i = MAXLOG - 1; i >= 0; i--)
for (int i = MAXLOG - 1; i >= 0; --i)
if (par[p][i] + 1 && h[par[p][i]] >= h[q]) {
//* ans += cost[p][i];
//** ans = max(ans, cost[p][i]);
......@@ -61,7 +61,7 @@ int query(int p, int q) {
return p;
//*** return ans;
for (int i = MAXLOG - 1; i >= 0; i--)
for (int i = MAXLOG - 1; i >= 0; --i)
if (par[p][i] + 1 && par[p][i] != par[q][i]) {
//* ans += cost[p][i] + cost[q][i];
//** ans = max(ans, max(cost[p][i], cost[q][i]));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment