#c221302. 等效电阻
等效电阻
Equivalent Resistance
Problem Description
You are given a circuit diagram with vertices and edges, the vertices numbered from to . Vertex is the positive terminal and vertex is the negative terminal, and the circuit is guaranteed to be connected.
An edge means there is a circuit between vertex and vertex with a resistor of resistance in the middle; there may be multiple parallel resistor branches between two vertices.
Now answer: what is the equivalent resistance of the whole circuit from vertex to vertex ?
Input Format
The first line contains two positive integers and , the number of vertices and edges.
The following lines each contain three integers , meaning there is a path with resistance between vertex and vertex .
The data guarantees that vertex and vertex are connected.
Output Format
Output one number on a line: the answer.
Your answer is accepted if its relative or absolute error from the standard answer is within .
Sample Input 1
3 3
1 2 1
1 2 1
2 3 2
Sample Output 1
2.5000000000
Sample Input 2
4 5
1 2 1
2 4 4
1 3 8
3 4 19
2 3 12
Sample Output 2
4.2098138748
Constraints
For of the data, $2 \leq n \leq 50, 1 \leq m \leq 2000, 1 \leq i, j \leq n, i \neq j, 1 \leq c \leq 10^4$.
Hint
Series circuit:
Parallel circuit:
For vertices other than the two terminals,
Equivalent resistance