diff --git a/graph/lca.cpp b/graph/lca.cpp index cffce0a2e4c55b6ba1e3ae4af400eea91fbb87b6..79f835dc898f4a580b9f547ae59b0679babbdbf1 100644 --- a/graph/lca.cpp +++ b/graph/lca.cpp @@ -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]));