how to build a circuit that compares two potentials?
You need a window comparator like this:



If R1 and R3 are equal and 10 times R2 you have reference voltages around 0.48 and 0.52 times the input voltage of the divider. Then use a :2 divider to get the other input voltage at 0.5 times its value. Then if the difference between the two voltages becomes larger than about 5% the output will go low. You can use the output to drive a small relay through a transistor.

Like ThePhoton comments the comparators have to be open drain/open collector types.