Problem : https://atcoder.jp/contests/abc148/tasks/abc148_f
How did you solved this problem? It would be better if you can give your intuition along with your approach.
Thank you.
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3611 |
| 4 | jiangly | 3583 |
| 5 | strapple | 3515 |
| 6 | tourist | 3470 |
| 7 | Radewoosh | 3415 |
| 8 | Um_nik | 3376 |
| 9 | maroonrk | 3361 |
| 10 | XVIII | 3345 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 162 |
| 2 | adamant | 148 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 143 |
| 5 | errorgorn | 141 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
Problem : https://atcoder.jp/contests/abc148/tasks/abc148_f
How did you solved this problem? It would be better if you can give your intuition along with your approach.
Thank you.
| Название |
|---|



This might help a bit.
Thank you :)
Let A be Aoki's initial position and T be Takahashi's initial position.
We root the tree at A. Then for Takahashi, the optimal strategy will be running to some parent of T (we call that parent P, P can be just T), and then from there run to the furthest leaf in the subtree rooted in P.
The three phases are:
(The distance between them - 1)We should only consider all P in which Takahashi can reach P before Aoki can reach P.
We can find the distance to the furthest leaf for all nodes using dp on tree. Then for each P, the total time taken is:
(The time needed to travel to P) + (The distance to the furthest leaf) + (The distance between Takahashi and Aoki after Takahashi reaches P - 1).We just take the maximum value for all valid P.
You can simplify it by observing that for each leaf k which Takahashi arrives earlier, that formula always reduces to (Distance between v and k) — 1. Since this value always has its maximum at a leaf, we can just write
Max{ for any node k with dist[u to k] < dist[v to k] } ( dist[v to k] - 1 )
My solution
You can solve this problem with dfs!
First make "Takahashi" as a root and write all vertices distance to root let call that disx[i](for vertex number i) and then make "Aoki" as a root and write all vertices distance to root let call that disy[i](for vertex number i) you should find:
maximum disy[i] such that disy[i] > disx[i] and the answer is (disy[i] — 1)
my solution