Editorial for Effortless
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Hints
- ||The constraints seem to imply that your solution should have complexity of
, but the sum of the actual answer could be more than this. So we can't count pairs one-by-one.||
- ||We need to separate the tree into families of pairs, which all follow the same logic (or maybe worded differently, find families of paths where the edges replaced are the same, and so the impact on distance is the same)||
- ||If you compute the path between the two portals, edges introduced to existing paths will only include and remove a selection of these edges - why?||
Solution
View Solution
Suppose we have portals at
2. Otherwise, the path from
As such, for any two pairs of nodes that would intersect the same points on the path from
@code_include[solutions/main.cpp]{rm_config: True, langs: "cpp,py"}
Comments