I have heard that in problem in 1775D - Friendly Spiders, the solution is to decomposition prime factor and do shortest pathes.
But won't it get TL in the system test? If all the numbers are prime and you need $$$3e5*\sqrt{3e5}$$$ to do that, and equals to 1e8.