Can anyone explain the centroid decomposition solution?

Before contest

Codeforces Round #606 (Div. 1, based on Technocup 2020 Elimination Round 4)

25:56:36

Register now »

Codeforces Round #606 (Div. 1, based on Technocup 2020 Elimination Round 4)

25:56:36

Register now »

*has extra registration

Before contest

Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

25:56:36

Register now »

Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

25:56:36

Register now »

*has extra registration

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

1 | tourist | 3556 |

2 | wxhtxdy | 3520 |

3 | Radewoosh | 3409 |

4 | Benq | 3368 |

5 | mnbvmar | 3280 |

6 | ecnerwala | 3278 |

7 | LHiC | 3276 |

8 | sunset | 3264 |

9 | maroonrk | 3159 |

10 | TLE | 3145 |

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

1 | Errichto | 189 |

2 | Radewoosh | 177 |

3 | tourist | 173 |

4 | antontrygubO_o | 172 |

5 | Vovuh | 167 |

6 | PikMike | 166 |

7 | rng_58 | 157 |

8 | majk | 156 |

9 | farmersrice | 153 |

9 | Um_nik | 153 |

Can anyone explain the centroid decomposition solution?

↑

↓

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/13/2019 12:08:24 (e1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Let's fix a current centroid (

root).So, if path

v-uwith lengthkexists and path contains vertexroot, we can split it to the two parts: from vertexvto therootand fromrootto vertexu. Note: vertexesvandumust be in different subtrees ofroot.Next, we process every subtreee of

rootfrom left to right (or another fixed order) by simple dfs(vertex, distance, edgecount), and collect map<distance, edgeCount> for each subtree (local), and one global map. Suppose now we are in vertexu, with distanceDand edgeCountE, we should check, that global map containsk-Dkey, and update answer if can (answer=min(answer,E+global[k-D]), and update min in local map. After subtree processing, we merge local map to the global.Thanks. This works because for the original centroid we would have to process N vertices in our DFS. And after splitting the tree, in the subsequent DFSs the number of nodes to process gets half. And therefore the complexity would be O(NlogN) excluding the map log factor. Right?

I think it's enough to use an array of size

kinstead of a map if we are careful about reusing it. This way we can getO(N logN)without any hashing (if one wanted to use a hash map to remove the log factor from using a map). This is the official solution and it can be found here.Where can we submit the problem?

http://wcipeg.com/problem/ioi1112