There was an error while loading. Please reload this page.
1 parent 76864a4 commit 9cc95dcCopy full SHA for 9cc95dc
Templates/binar_lifting.cpp
@@ -0,0 +1,70 @@
1
+
2
3
+ll dp[200005][20];
4
5
6
7
+void binlift(){
8
+ for(ll i=1;i<20;i++){
9
+ for(ll j=0;j<n;j++){
10
+ if(dp[j][i-1]==-1){
11
+ dp[j][i]=-1;
12
+ continue;
13
+ }
14
+ dp[j][i]=dp[dp[j][i-1]][i-1];
15
16
17
18
19
+}
20
21
22
+ll query(ll x,ll k){
23
+ ll prev=x;
24
+ for(ll i=20;i>=0;i--){
25
+ if((k>>i)&1){
26
+ // cout<<i<<"i"<<endl;
27
+ prev=dp[prev][i];
28
+ if(prev==-1){
29
+ break;
30
31
32
33
34
+ return prev;
35
36
37
38
39
40
41
42
43
+int main(){
44
+ ios_base::sync_with_stdio(false);
45
+ cin.tie(NULL);
46
47
48
49
50
51
52
+ memset(dp,-1,sizeof(dp));
53
54
+ for(ll i=0;i<n;i++){
55
+ dp[i][0]=parent[i];
56
57
58
+ binlift();
59
60
61
62
63
64
65
66
67
68
69
+ return 0;
70
0 commit comments