#P3617. 电阻网络
电阻网络
Description
Cjwssb recently encountered a tough problem in physics. He does not know how to compute the equivalent resistance of a circuit. He turned to you for help.
This circuit satisfies the following constraints:
- The circuit consists only of wires and resistors of .
- The circuit is connected from left to right, that is, for every resistor or wire with endpoints , it holds that .
- Node is the positive terminal of the power supply, and node is the negative terminal.
- Each node is either unused, or serves as the junction of exactly two branch subcircuits that are connected either in series or in parallel.
Input Format
The first line contains two positive integers , the numbers of nodes and resistors. Nodes are numbered from left to right, so a smaller index is to the left of a larger index.
Each of the next lines contains three integers , meaning there is a resistor between nodes and with resistance , where is either or , and for every it is guaranteed that .
Output Format
Output a real number, the total resistance, rounded to three decimal places.
7 7
1 2 0
1 3 0
2 4 1
3 5 1
4 6 0
5 6 0
6 7 1
1.500
Hint
[Sample Explanation]
Draw the diagram and the answer is obvious.
[Constraints]
| Score | ||
|---|---|---|
P.S. The testdata are randomly generated under a fixed , and the answer is guaranteed not to exceed 10 000.
By: saffah.
Translated by ChatGPT 5
京公网安备 11011102002149号