Social Resistance

From programming_contest
Jump to navigation Jump to search

This problem asks us to calculate the equivalent resistance between two nodes in a resistor circuit with all 1 ohm resistors.

Given that no simplifications are guaranteed, we must need a general way of solving this....depending largely on kirchoff's circuit law (AKA rule 1, KCL).

The problem strongly hints at the solution with its description of V1 and V2. We can create variables for the voltages at every node, and then attempt to solve.

At each node, we can write a single equation based on KCL balancing the current in and out:

for all i:
for all j neighboring i:
0 = sum(Vj-Vi)
# note, normally we divide by r, but r is 1
# note 2, the current at the first or last nodes equal 1 and -1

This gives us N equations and N unknowns. We pop it into a gaussian elimination solver, and presto. Then the voltage difference between the start and end node divided by the current (which we fixed at 1) equals the equivalent resistance (rule 2, ohm's law).

The input size is plenty small enough for this to work.