You need two of these
View attachment 335333
one for each loop. Cut a hole in the side of the slot so the tab protrudes across the slot, the tab might need bending to get it to work properly with the cars guides.
You also need one of theses, 2 pole 2 way latching relay
View attachment 335335
and the wiring diagram
View attachment 335336
The micro switches are SWW1 and SW2, from power supply should read from controller. Unlike with a traditional relay that requires the power to be on to the coil to hold the relay closed and power of to be open two coil latching relays only need the coil to be activated for a momment to move the contact and it stays in that state until the other coil is activated. If we say the diagram shows the track for going from loop one to loop two the top track rail is -ve and the bottom is +ve. When the cars passes the second loop switch it is closed as the car passes activating one of the coils and, in the diagram, the contacts move down and stay there. This switches the power to the track so the top rail is now +ve with the bottom rail -ve. When the car goes around the first loop SW1 is closed for a moment and the other coil is activated, just for a moment, and moves the contacts back to the up position as shown in the diagram again reversing the power to the track. You also need two extra feed lines from the 'power supply' + and - going to each of the isolated loops. As long as the loops are designed so the car can only enter one way nothing else is needed.
If you wish you can replace the micro switches with opto-couplers but you would then need to use a micro controller board to read the coupler and activate the relay coils. This would also allow you to use a standard relay with the appropriate coding. If the cars are fitted with magnets it might also be possible to use reed switches in place of the micro switches or hall sensors in place of the opto-couplers.