POJ 2763 "Housewife Wind" (DFS + Sequence + Fenwick tree the LCA)

 

Portal

 

• the meaning of problems

  A couple living in the village of xx, to the village there are $ n $ cabins;

  There are up to two-way road between $ n $ cabins, will not ring, that figure is composed of a tree;

  From $ a_i $ cottages to $ b_i $ $ w_i $ lodge takes time;

  Initially, the female lead in the $ s $ No. cabins, there are q times asked each one to ask for the following two:

    • 0 u: she had a child in the $ u $ house number, you need to take her home mom, output from $ s $ to $ u $ in the shortest time
    • 1 x val: For various reasons, before consuming the $ w_x $ of $ x $ roads becomes a $ val $

•answer

  

  Consider the structure as shown, some inconvenience in operation of the tree, so we need to be serialized;

  The tree shown above, which was converted to DFS sequence;

  $ 1 \ {overlooked W_} {1,2} {\ right arrow 2} \ {overlooked W_} {2,4} {\ right arrow 4} \ {overlooked -w_ {2,4}} {\ leftarrow 2} \ {overlooked W_} {2,5} {\ right arrow} 5 \ overlooked -w_ {{2.5} {} \} 2 left arrow \ overlooked -w_ {{1,2}} {\ leftarrow} 1 \ overlooked W_ {{1 , 3}} {\ right arrow 3} \ {overlooked -w_ {1,3}} {\ leftarrow} $ 1

  And to make the weight in the positive direction of the leaf, the root along the direction is negative;

  Then the position from the position of the first occurrence of $ u $ to $ v $ first appears, do not belong to $ u, v $ edge on the path will be offset;

  Then there are:

    $ (U, v) the distance between $ a = (from $ LCA (u, v) $ to $ U $ of the weight of an edge and) + (from $ LCA (u, v) $ to $ V $ sides and weights)

  Because it is a single point update, so we can consider to use DFS Fenwick tree to maintain order;

Guess you like

Origin www.cnblogs.com/violet-acmer/p/11782617.html