Jratos's blog

By Jratos, history, 6 weeks ago, In English

Hi, is there a reason why my submission* got accepted meanwhile my rough estimate for time complexity is O(n^3), because i did a dfs and for every node i calculate a subset sum of each subtree size. Or is this because of weak tc? thanks

*) https://mirror.codeforces.com/contest/1856/submission/290385616

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it +7 Vote: I do not like it

The time complexity will be O($$$n^2$$$). For each node we iterate through it's children and the number of parent-children pairs is n-1. We then calculate the subset sum in O($$$n$$$) leading to O($$$n^2$$$).