optimized optimal algorithm for coloring