FutureIntelli's blog

By FutureIntelli, history, 4 weeks ago, In English,

Any approach to solve this problem. As expected making dfs calls from every vertex results in TLE

Thanks in advance!

 
 
 
 

»
4 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

calculate k[i]th ancestor of each node and subtract r[i`] from that node and store in arr[], simultaneously add r[i] to the current node. Now population of each country can be calculated using another dfs by that additional array arr[]