#3515
Shortest Path in a Weighted Tree
master · 1650 · lc hard +32 · 42.2% accepted · 63 likes · top 23%
Description
A weighted tree with n nodes (rooted at node 1) is given via edge list edges[i] = [ui, vi, wi]. Process queries of two types:
- [1, u, v, w\']: Update the weight of edge (u, v) to w\'.
- [2, x]: Report the shortest path distance from root 1 to node x.
Return all answers for type-2 queries in order.
Code
1
2
3