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.

# | User | Rating |
---|---|---|

1 | tourist | 3778 |

2 | Benq | 3592 |

3 | ecnerwala | 3521 |

4 | Um_nik | 3423 |

5 | jiangly | 3375 |

6 | Petr | 3342 |

7 | Radewoosh | 3337 |

8 | scott_wu | 3313 |

9 | maroonrk | 3265 |

10 | yosupo | 3259 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 201 |

2 | 1-gon | 200 |

3 | rng_58 | 194 |

4 | SecondThread | 193 |

5 | awoo | 186 |

6 | vovuh | 183 |

7 | Um_nik | 182 |

8 | antontrygubO_o | 177 |

9 | Ashishgup | 175 |

10 | -is-this-fft- | 171 |

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.

↑

↓

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jan/23/2021 01:18:16 (f1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Codeforces Round #527 (Div. 3) Problem F

thanks

https://codeforces.com/contest/1324/problem/F

Well done, would you join our Clan!

ok (clan like some group for practicing algos and problems i assume).

https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/practice-problems/algorithm/parwal-problem/

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

This comment have few more nice problems on rerooting.

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

this one: Atcoder dp_v

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)

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.

can you please elaborate more or share the link of your code

Here you go: submissiom

NOTE: My code is a little ugly.

![](https://i.imgur.com/2vVTfEs.jpg) Instead of dividing the product of the whole array by x, we can compute prefix * suffix

Can Someone explain What is rerooting?

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.The blog from where I learnt rerooting:-link

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

766 E.

https://atcoder.jp/contests/abc160/tasks/abc160_f

https://atcoder.jp/contests/abc149/tasks/abc149_f

This link was really helpful

sorry brother i downvoted it by mistake so sorry for that

https://codeforces.com/contest/219/problem/D https://codeforces.com/problemset/problem/615/B

https://atcoder.jp/contests/abc160/tasks/abc160_f

https://atcoder.jp/contests/abc149/tasks/abc149_f

https://codeforces.com/contest/1187/problem/E

https://codeforces.com/contest/1092/problem/F

https://codeforces.com/contest/1324/problem/F

https://atcoder.jp/contests/dp/tasks/dp_v

https://codeforces.com/contest/960/problem/E

https://cses.fi/problemset/task/1132

https://cses.fi/problemset/task/1133

https://dmoj.ca/problem/dmopc14c4p6

https://oj.uz/problem/view/CEOI17_chase

https://dmoj.ca/problem/cco13p3

https://dmoj.ca/problem/coci08c1p6

Collected from various blogs. It might help.

This is quite a nice one!