MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / solve

Function solve

Trees/LCA.cpp:53–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53void 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}
73int main()
74{
75 solve();

Callers 3

mainFunction · 0.70
solveSudokuMethod · 0.50
solveMethod · 0.50

Calls 3

preprocessFunction · 0.85
lcaFunction · 0.85
push_backMethod · 0.80

Tested by

no test coverage detected