Блог пользователя issahaddar5

Автор issahaddar5, история, 11 лет назад, По-английски

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.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
11 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

This is an unrooted tree. Which means you don't know Fr is the parent or To is.

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится -23 Проголосовать: не нравится

.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится -25 Проголосовать: не нравится

D.collision This is a similar problem. Give it a try!!