CBPF is Color Based PathFinding, this is going to be a setup for color based or nonshaped pathfinding and mapping (which means you don't need all of them to be squares for the thing to work) to use it - first you need to not use any pure white, as in brightness 100, saturation 0, as it uses that for the system then you need to use your clone ID to replace the one I am using, finally set the labeled repeat to however many provinces you have and run the script, it should work but if you have issues, just ask in the comments you also should not need to use it several times as this sets up borders, unless you need to change the province borders regularly
I am reusing some older assets for the example