-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ adds successor graph with binary lifting
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const int MAXLG2 = 31; | ||
struct FunctionalGraph { | ||
int n; | ||
vi g; | ||
vi2d bl; | ||
|
||
FunctionalGraph(int _n) | ||
: n(_n), g(n), bl(n, vi(MAXLG2)){}; | ||
|
||
FunctionalGraph(const vi &_g) | ||
: n(len(_g)), g(_g), bl(n, vi(MAXLG2)){}; | ||
|
||
void build() { | ||
for (int i = 0; i < n; i++) { | ||
bl[i][0] = g[i]; | ||
} | ||
for (int k = 1; k < MAXLG2; k++) { | ||
for (int i = 0; i < n; i++) { | ||
bl[i][k] = bl[bl[i][k - 1]][k - 1]; | ||
} | ||
} | ||
} | ||
|
||
int kth_pos(int u, ll k) const { | ||
for (ll i = 0; i < MAXLG2; i++) | ||
if (k & (1 << i)) u = bl[u][i]; | ||
|
||
return u; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\subsection{Succesor Graph (Struct Binary-Lifting)} |