Interesting Resister Graph

A graph G has n nodes, v1, v2, ..., vn such that vi is connected to vi+1 for 0 ≤ i ≤ n−2. The last node, vn is connected to all nodes vj for 0 ≤ j ≤ n−1. Each edge of the graph has a single resistor with resistance of 1 ohm. Given 2 nodes, vi and vj, find the equivalent resistance between these 2 nodes. Note that when we add a power source to the 2 nodes with I amperes, then each node on the graph has some fixed voltage, and each edge has some fixed current, such that the inward current equals the outward current on each node that is not vi (has net input current I) and not vj (has net output current J). Moreover, Ohm’s law is followed, which says that R = V /I, where I is the current in amperes, V the voltage in volts and R the resistance in ohms. This is all the information needed to solve the problem. Input A number of of inputs (≤ 10000), each starting with n, i, j on a line (1 ≤ i < j ≤ n ≤ 10000). Output For each input, output the equivalent resistance between vi and vj , rounded to 6 digits after the decimal. Sample Input 312 313 Sample Output 0.298142 0.447214