S_Aditya's blog

By S_Aditya, history, 19 months ago, In English

I have recently learnt the rerooting technique from the previous contest. I will be greatful if someone will please share some problems related to it.

 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

thanks

»
10 months ago, # |
  Vote: I like it 0 Vote: I do not like it
»
10 months ago, # |
Rev. 3   Vote: I like it +5 Vote: I do not like it

1187E - Tree Painting One of the best problem on rerooting!!

»
10 months ago, # |
  Vote: I like it +1 Vote: I do not like it

This comment have few more nice problems on rerooting.

»
10 months ago, # |
  Vote: I like it +1 Vote: I do not like it

This one was fun to work out: https://codeforces.com/contest/960/problem/E

»
10 months ago, # |
  Vote: I like it +16 Vote: I do not like it

this one: Atcoder dp_v

  • »
    »
    10 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    if we use rerooting in this problem, won't we have to use modular inverse at some point, and it is not neccesary that the modular inverse would exist with respect to m.

    (please correct me if I am wrong)

    • »
      »
      »
      10 months ago, # ^ |
        Vote: I like it +19 Vote: I do not like it

      No, for an array if we want to know for every number, the product of other numbers, we can achieve it by storing the prefix product and suffix product.

»
10 months ago, # |
  Vote: I like it +6 Vote: I do not like it

Can Someone explain What is rerooting?

  • »
    »
    10 months ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    In rerooting, what we basically do is first calculate the required data by considering some node as the root of the tree.

    In rerooting type problems, it is required to calculate the same data by considering each and every node as the root, using naive approach would result in tle.

    So, what we try do is using the calculated values(say by considering 1 to be the root), we try to calculate the answer for each node(if we assume that node to be the root) in O(1) time.

    Consider a case in which node is the current root and it is one of it's child, so it would had contributed something in the answer of node, so now we try to make it as the new root, so first we remove the contribution of it from node, then node is now a child for it, so we add the contribution of the subtree with root being node to the answer of it and now it has become the new root of the tree.

    But when we need to calculate the answer for say it1(second child of node) , we have to rollback the changes we made.

»
10 months ago, # |
  Vote: I like it +2 Vote: I do not like it

The blog from where I learnt rerooting:-link

»
10 months ago, # |
  Vote: I like it 0 Vote: I do not like it

One more problem based on the concept : 1324F - Maximum White Subtree

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it
»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

This link was really helpful

»
7 months ago, # |
  Vote: I like it 0 Vote: I do not like it

sorry brother i downvoted it by mistake so sorry for that

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

This is quite a nice one!