If the tree structure changes at runtime with edges being added or removed, you cannot use static rerooting. You need dynamic tree data structures like Link-Cut Trees or Euler Tour Trees. If only node values change but the structure stays fixed, you might be able to use rerooting combined with segment trees or other range query structures.
These scenarios are rare in competitive programming. Most rerooting problems have a static tree that does not change. Focus on the static case first.