Tree conversion chain split point on the right side and the right

Because it is a tree, it may be directly between the points u and the point v (assuming u parent node, child node v) down the side to the right side of the point v

This converted into the right point, then the time query point to the weight u v path between points and then

Since there point u u u parent node to the right side, so that query is the second point on the path from u to v, and the weights v

 

Modifying the query function tree between two nodes path length
 int QueryPath ( int X, int Y)} { 
seek last step portion 

/// point right version 
IF (P [X]> P [Y]) the swap (X , Y);
 return ANS Query + (P [X], P [Y], . 1 , POS, . 1 );
 /// edge weight version 
IF (X == Y) return ANS;
 IF (DEP [X]> DEP [Y]) the swap (X, Y);
 return ANS Query + (P [Son [X]], P [Y], the root);

 

Guess you like

Origin www.cnblogs.com/shuaihui520/p/11200900.html