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 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 165 |
2 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
4 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
8 | Dominater069 | 154 |
8 | nor | 154 |
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