Travelling salesman. Final speed/memory optimizations