Problem. I checked various solutions. I could see DSU and Dynamic programming in most of them. Any hint or full solution would be helpful.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Problem. I checked various solutions. I could see DSU and Dynamic programming in most of them. Any hint or full solution would be helpful.
Name |
---|
Here's a very similar problem on an Educational round. I would recommend understanding the solution based on centroid decomposition (even though it isn't strictly required here), since it is much more general and can solve a variety of problems of this kind, i.e., obtaining information about all paths in a tree.
It's actually the SAME problem. Shame on the codechef author :(
Funnily enough, I actually ACed the Educational Round problem before the CodeChef contest, but kept TLEing on the CodeChef version of the problem (I never thought to check my old CF submissions during contest :( ).
The decrease of the TL from 4.5 seconds to 3.0 seconds in addition to there being 10 testcases v.s. 1 testcase in an input is highly annoying, as it required several relatively hacky optimizations (e.g. precomputing the GCD >= 1 case) to make a modification of the Educational Round solution pass (and still doesn't make it qualify as a unique problem).
/endsalt
Is there a better complexity solution that CodeChef expected?