Brute force runs BFS from every node. Each BFS takes , so the total is . For , that is operations. At operations per second, it takes seconds. Way too slow.
Rerooting does DFS passes, each . Total: . For , that is about operations. It finishes in under a millisecond.
The speedup comes from reusing work. Each edge transition costs instead of . You trade full DFS traversals for constant-time updates. That is an -fold improvement.