Kyopro Library
読み取り中…
検索中…
一致する文字列を見つけられません
doubling.hpp
[詳解]
1
#
include
"../../kyopro_library/template.hpp"
2
3
/// @brief ダブリング
4
/// @param Log ダブリングの深さ
5
template
<
int
Log>
6
struct
Doubling
{
7
Doubling
()=
default
;
8
9
/// @brief コンストラクタ
10
/// @param v 各頂点からの遷移先
11
/// @note O(N Log)
12
Doubling
(
const
vector<
int
>& v) {
13
int
n=v.size();
14
nxt=vector<vector<
int
>>(Log+1,vector<
int
>(n));
15
for
(
int
i=0; i<n; i++) nxt[0][i]=v[i];
16
for
(
int
i=0; i<Log; i++)
for
(
int
j=0; j<n; j++) nxt[i+1][j]=nxt[i][nxt[i][j]];
17
}
18
19
/// @brief 頂点 start から k 回遷移した先の頂点を返す
20
/// @note O(Log)
21
int
next
(
int
start, ll k) {
22
for
(
int
b=0; k>0; b++,k>>=1)
if
(k&1) start=nxt[b][start];
23
return
start;
24
}
25
26
private
:
27
vector<vector<
int
>> nxt;
28
};
Doubling
ダブリング
Definition
doubling.hpp:6
Doubling::next
int next(int start, ll k)
頂点 start から k 回遷移した先の頂点を返す
Definition
doubling.hpp:21
Doubling::Doubling
Doubling(const vector< int > &v)
コンストラクタ
Definition
doubling.hpp:12
Doubling::Doubling
Doubling()=default
algorithm
doubling.hpp
構築:
1.13.2