Total Depth — Solution & Editorial
One BFS/DFS accumulating depths — a warm-up for the rerooting technique.
Complexity: O(N)
Watch out: The total reaches ~5×109 on a path — 64-bit.
One BFS/DFS accumulating depths — a warm-up for the rerooting technique.
Complexity: O(N)
Watch out: The total reaches ~5×109 on a path — 64-bit.