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.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3741 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3489 |
7 | Radewoosh | 3483 |
8 | Kevin114514 | 3442 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | atcoder_official | 162 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | nor | 150 |
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.
Name |
---|
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