Please read the new rule regarding the restriction on the use of AI tools. ×

Distance Between Nodes in A General Tree

Revision en1, by issahaddar5, 2015-09-06 13:18:09

I am trying to solve this. The graph is a tree, so I represented it as disjoint sets. To find the distance between two nodes I am finding the first common ancestor and adding the distances to reach this ancestor form the starting node and the target node. this is my code and unfortunately its giving wrong answer upon submission.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English issahaddar5 2015-09-06 13:18:09 436 Initial revision (published)