fork download
  1.  
  2. int queryKthNode(int u, int v, int k) {
  3. int lca = LCA(u, v);
  4. if (depth[u] > depth[v]) {
  5. std::swap(u ,v);
  6. }
  7. if (depth[u] - depth[lca] > k) {
  8. k = 1 + depth[u] + depth[v] - 2*depth[lca] - k;
  9. }
  10. int kthNode = -1;
  11. for (int i = 14; i >= 0; i--) {
  12. if(k - (1 << i) >= 0) {
  13. k -= (1 << i);
  14. if (kthNode == -1) {
  15. kthNode = pa[i][u];
  16. } else {
  17. kthNode = pa[i][kthNode];
  18. }
  19. }
  20. }
  21. return kthNode;
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int queryKthNode(int, int, int)':
prog.cpp:3:23: error: 'LCA' was not declared in this scope
     int lca = LCA(u, v);
                       ^
prog.cpp:4:9: error: 'depth' was not declared in this scope
     if (depth[u] > depth[v]) {
         ^
prog.cpp:5:9: error: 'swap' is not a member of 'std'
         std::swap(u ,v);
         ^
prog.cpp:7:9: error: 'depth' was not declared in this scope
     if (depth[u] - depth[lca] > k) {
         ^
prog.cpp:15:27: error: 'pa' was not declared in this scope
                 kthNode = pa[i][u];
                           ^
prog.cpp:17:27: error: 'pa' was not declared in this scope
                 kthNode = pa[i][kthNode];
                           ^
stdout
Standard output is empty