#P4020. [CTSC2012] 电阻网络

    ID: 2951 远端评测题 4000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>递推2012WC/CTSC/集训队Special Judge高斯消元

[CTSC2012] 电阻网络

Description

Given a tree-shaped circuit, each edge in the tree has a resistor RiR_i, and all resistances are 10000 Ω10000\ Ω. The figure below shows a tree-shaped circuit with 44 nodes:

Figure 1

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

Figure 2

There are two types of operations:

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

Figure 3

Q u: Query the current voltage of node uu, measured with respect to ground.

After performing C 2 4 5 on the figure above, the network becomes:

Figure 4

At this time, the voltage at each node is as labeled in the figure.

Input Format

The input file circuit.in contains two integers N,MN, M on the first line, representing the number of nodes in the tree and the number of operations, respectively. The next N1N-1 lines each contain two integers u,vu, v, indicating that there is an edge connecting nodes uu and vv, and this edge contains exactly one resistor.

Then there are MM 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 10310^{-3}.

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 Ui>UjU_i > U_j, there would be current flowing from ii to jj, contradicting the absence of a source). They are all equal to the ground potential 0V0\text{V}.

After adding a 5V5\text{V} voltage source on (2,4)(2, 4), the new circuit is as shown in the problem statement.

After simplification, the new circuit can be seen as series (source, R2+10000R_2+10000, parallel (R1+10000R_1+10000, R3+10000R_3+10000)), 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 44 is 530000 A\frac{5}{30000}\ A, so U4=53VU_4=\frac{5}{3}V and U2=U4+R2I5=53VU_2=U_4+R_2\cdot I-5=-\frac{5}{3}V; since U1U_1 and U3U_3 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]

30%30\% of the testdata guarantees N,M30N, M ≤ 30.

60%60\% of the testdata guarantees N,M3000N, M ≤ 3000.

100%100\% of the testdata guarantees 3N,M500003 ≤ N, M ≤ 50000, 1u,vn1 ≤ u, v ≤ n, 1w101 ≤ w ≤ 10, and the length of the longest chain in the tree does not exceed 5050.

Translated by ChatGPT 5