Skip to content

Commit

Permalink
Fix __lg(0) case and update description
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanRenison committed May 12, 2024
1 parent d6c796d commit 5644ad7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions content/graph/BinaryLifting.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* Source: Folklore
* Description: Calculate power of two jumps in a tree,
* to support fast upward jumps and LCAs.
* Assumes that P is not empty and that the root node points to itself.
* Assumes the root node points to itself.
* Time: construction $O(N \log N)$, queries $O(\log N)$
* Status: Tested at Petrozavodsk, also stress-tested via LCA.cpp
*/
#pragma once

vector<vi> treeJump(vi& P){
int d = 1 + __lg(sz(P) - 1);
int d = sz(P) < 2 ? 0 : 1 + __lg(sz(P) - 1);
vector<vi> jmp(d, P);
rep(i,1,d) rep(j,0,sz(P))
jmp[i][j] = jmp[i-1][jmp[i-1][j]];
Expand Down

0 comments on commit 5644ad7

Please sign in to comment.