| 51 | } |
| 52 | |
| 53 | void solve(){ |
| 54 | int q; |
| 55 | cin>>n>>q; |
| 56 | adj.resize(n + 1); |
| 57 | for(int i = 1;i < n;i++){ |
| 58 | int x; |
| 59 | cin>>x; |
| 60 | x--; |
| 61 | adj[x].push_back(i); |
| 62 | adj[i].push_back(x); |
| 63 | } |
| 64 | preprocess(0); |
| 65 | while(q--){ |
| 66 | int x, y; |
| 67 | cin>>x>>y; |
| 68 | x--;y--; |
| 69 | int ans = lca(x, y); |
| 70 | cout<<ans + 1<<endl; |
| 71 | } |
| 72 | } |
| 73 | int main() |
| 74 | { |
| 75 | solve(); |
no test coverage detected