Dynamic programming

Kinda confused what links_to_dists is for