Rerooting problems often say "for each node" or "for all possible roots" in the problem statement. That is your signal to think about rerooting. If brute force is and constraints are or , you need or . Rerooting gives you , which is often the intended solution.
After solving a few rerooting problems, you will see the pattern immediately. The hard part is setting up the DP state and combine function correctly, not the two-pass structure itself. That stays the same across all problems.
Space complexity is for the data structures used.