Search
⌘K

Leetcode 3515. Shortest Path in a Weighted Tree

Maintain distances from root in a rooted weighted tree under two operations: update the weight of a single edge and query the shortest-path distance from the root to a given node. Key insight — changing an edge weight adds a constant delta to all nodes in the edge's child subtree, so you need a data structure that supports many subtree range-updates and point-distance queries efficiently.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.