fork download
  1. int KthNode(int k,int u,int v)
  2. {
  3. int lca = LCA(u,v) ; // O(logN) method to find LCA
  4. if(lca==u)
  5. {
  6. int d = depth[v] - depth[u] + 1 ;
  7. swap(u,v);
  8. k = d - k + 1 ;
  9. }
  10. else if(lca==v);
  11. else {
  12. if(k > depth[u]-depth[lca]+1) {
  13. d = depth[u] + depth[v] -2*depth[lca] + 1;
  14. k = d - k + 1 ;
  15. swap(u,v);
  16. }
  17. }
  18. for(int i=LG;i>=0;--i) {
  19. if(k & (1<<i)) {
  20. u = parent[i][u] ; // parent matrix precomputed for finding LCA
  21. }
  22. }
  23. return u;
  24. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int KthNode(int, int, int)':
prog.cpp:3:22: error: 'LCA' was not declared in this scope
     int lca = LCA(u,v) ; // O(logN) method to find LCA 
                      ^
prog.cpp:6:17: error: 'depth' was not declared in this scope
         int d = depth[v] - depth[u] + 1 ; 
                 ^
prog.cpp:7:17: error: 'swap' was not declared in this scope
         swap(u,v);
                 ^
prog.cpp:12:16: error: 'depth' was not declared in this scope
         if(k > depth[u]-depth[lca]+1) {
                ^
prog.cpp:13:13: error: 'd' was not declared in this scope
             d = depth[u] + depth[v] -2*depth[lca] + 1;
             ^
prog.cpp:15:21: error: 'swap' was not declared in this scope
             swap(u,v);
                     ^
prog.cpp:18:15: error: 'LG' was not declared in this scope
     for(int i=LG;i>=0;--i) {
               ^
prog.cpp:20:17: error: 'parent' was not declared in this scope
             u = parent[i][u] ; // parent matrix precomputed for finding LCA 
                 ^
stdout
Standard output is empty