Luo Gu $ P1600 $ jogging every day, love trees differential

Positive Solutions: a tree difference

Report problem solving:

Portal $ QwQ $!

This question quite wonderful and, I think for a long time will be $ kk $

First, a chain $ ST $, consider first split it into $ S-LCA $ and $ LCA-T $, respectively, to do, because on the whole, then I almost only port $ S-LCA $ approach the $ QwQ $

Consider an observation point for $ j $, to observe the player $ i $, there are $ dep_j + w_j = dep_i $. Now found only in the statistical $ j $ subtree starting point for all depth equal to $ dep_j + w_j $ on the line.

Consider the tree apparent difference pictures. Buckets referred to open $ dep_i $, on each path to $ dep_S $ + 1 at the $ S $, $ to give at the LCA $ $ dep_S-1 $, on each observation point and then The answer directly check $ t_ {dep_j + w_j} $ get away $ QwQ $.

Then almost $ LCA-T $? Will become the next expression, attention to detail under, $ over $

Ow then finally a point, in fact, this path should be split into $ S-LCAson $ and $ LCA-T $ a, $ over $

Guess you like

Origin www.cnblogs.com/lqsukida/p/11428923.html