Project Euler #107: Minimal network