Company: LinkedIn
Difficulty: medium
Remove Vulnerable Servers A rooted tree of servers is rooted at server `1`. Server `i` has threshold `a[i]`; every edge has a signed activity change. A server `u` is vulnerable if a remaining proper descendant `v` can receive a signal from `u` whose path-sum is greater than `a[v]`. You may repeatedly remove a leaf server. Find the minimum number of removals required so that no remaining server is vulnerable. Input Format The first line contains `n`. The second line contains `a[1..n]`. Each of the next `n-1` lines contains `u v w`, an undirected tree edge with activity change `w`. Output Format Print the minimum number of removed servers. Constraints `1 <= n <= 100000`, `|a[i]|, |w| <= 10^9`. Example Input 7 8 -11 -13 3 31 -13 12 1 2 -10 2 3 23 1 4 -7 1 5 -9 2 6 -13 2 7 23 Output 4 Notes A removed server removes its entire descendant branch over successive leaf removals.