Both writing an algorithm from scratch and copypasta lead to ineffective software engineering and computer science.
I would first look in the 5 book TAOCP for an algorithm recipe.
Then, I would look to other FOSS implementations that solved a particular problem before.
If you need to write something totally new, consider first why you must put dense engineering effort into something that may already exist. Do you really need to be solving this problem?
Because in order to achieve the highest performance, the only way to do it is draw a direct path from origin to the destination. Often the system is build around certain data structure to gain the maximum performance and cannot hot swap that part. And you don't need to pull everything from amateur FOSS software to bloat your project.
You sound like ChatGPT with hyperbolic, loaded language.
I wouldn't call the Python dict implementation amateur.
Furthermore, the only way to arrive at optimal implementations for various platforms is to benchmark them. You won't get that just guessing or labeling things you know nothing about "amateur".
I would first look in the 5 book TAOCP for an algorithm recipe.
Then, I would look to other FOSS implementations that solved a particular problem before.
If you need to write something totally new, consider first why you must put dense engineering effort into something that may already exist. Do you really need to be solving this problem?