We can use Eratosthese’s Sieve to factorize the numbers in .
Note: There are only 4792 primes below
Calculate the area of triangle using
To use Heron’s formula, you should square root each factor before multipling them together.
Sort all pairs of , and put them into a set (using binary tree).
Maintain a list (or double linked list) of adjacent triangles.
In each step, find the smallest triangle, and two adjacent triangles.
Remove the middle (smallest) triangle from the set, and modify two adjacent triangles.
Construct DAG graph
Use dynamic programming to find the optimum path.
Simulation & Computational Geometry
Need a good Geometry template.
Tag: minimum cut / maximum flow
Some more explaination for the provided editorial: the left pipes are potential profit, and the right pipes are the profits “eaten up” by digging other blocks.