#P4020. [CTSC2012] 电阻网络
[CTSC2012] 电阻网络
Description
Given a tree-shaped circuit, each edge in the tree has a resistor , and all resistances are . The figure below shows a tree-shaped circuit with nodes:

All leaf nodes in the tree (nodes of degree are called leaves) are connected to ground, each line is connected to ground, and each line carries a resistor, forming the network shown below:

There are two types of operations:
C u v w: Insert a voltage source in series on edge , with magnitude volts. The source is placed on the side closer to node (as shown below), with its negative terminal pointing toward . Note that multiple voltage sources can be inserted in series on the same edge.

Q u: Query the current voltage of node , measured with respect to ground.
After performing C 2 4 5 on the figure above, the network becomes:

At this time, the voltage at each node is as labeled in the figure.
Input Format
The input file circuit.in contains two integers on the first line, representing the number of nodes in the tree and the number of operations, respectively. The next lines each contain two integers , indicating that there is an edge connecting nodes and , and this edge contains exactly one resistor.
Then there are lines, each containing one command in the format described above.
Output Format
Output to circuit.out. For each Q command, output a single number representing the voltage at that node at that moment. You may print any number of decimal places; your answer is considered correct if it differs from the standard answer by at most .
4 3
1 2
2 3
2 4
Q 2
C 2 4 5
Q 2
0.0000000000
-1.6666666666
Hint
[Sample Explanation]
For the first query, since there is no voltage source in the original circuit, there is no current, and all node voltages are equal (otherwise, if there exists , there would be current flowing from to , contradicting the absence of a source). They are all equal to the ground potential .
After adding a voltage source on , the new circuit is as shown in the problem statement.
After simplification, the new circuit can be seen as series (source, , parallel (, )), hence the equivalent resistance is:
$$R 2 +10000+\frac{1}{\frac{1}{R_3 +10000}+\frac{1}{R_1 +10000}}=30000\ Ω$$Therefore, the current flowing through node is , so and ; since and are symmetric, by the voltage division relation we have $U_1 =U_3 =U_2\times\frac{10000}{10000+10000}=-\frac{5}{6}V$.
[Constraints]
of the testdata guarantees .
of the testdata guarantees .
of the testdata guarantees , , , and the length of the longest chain in the tree does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号