#P2011. 计算电压

    ID: 955 Type: RemoteJudge 1000ms 125MiB Tried: 0 Accepted: 0 Difficulty: 8 Uploaded By: Tags>字符串数学高斯消元

计算电压

Description

You are given a resistor network. The resistance on each edge is known, and the voltages between several nodes and the negative terminal are given (the power-supply voltage is constant). Now compute the voltage between any two nodes.

Input Format

The first line contains four positive integers n,m,k,qn, m, k, q, indicating there are nn nodes (some nodes may be connected by wires and thus are equivalent to one node; nodes are numbered 11 to nn, and node 00 is the negative terminal of the power supply), mm fixed resistors (each fixed resistor connects two nodes), the positive terminal of the power supply has kk terminals, and there are qq queries.

The next kk lines each contain two positive integers, indicating the index of this positive terminal and the voltage uiu_i between this binding post and the negative terminal.

The next mm lines each contain three positive integers vi,wi,riv_i, w_i, r_i, indicating that there is a resistor of resistance rir_i between nodes viv_i and wiw_i.

The next qq lines each contain two positive integers ai,bia_i, b_i, indicating that you need to compute the voltage between aia_i and bib_i.

Output Format

Output qq lines. Each line contains one real number representing the voltage between aia_i and bib_i (rounded to two decimal places). If the voltage at aia_i is less than the voltage at bib_i, output a negative value.

3 5 1 3
1 18
1 2 6
1 3 2
2 3 6
3 0 6
2 0 2
1 0
2 3
1 2

18.00
-6.00
12.00

Hint

Constraints

  • For 10%10\% of the testdata, 1q101 \le q \le 10.
  • For 20%20\% of the testdata, 1n101 \le n \le 10, and the circuit is guaranteed to be series, parallel, or a mixed connection.
  • For 40%40\% of the testdata, 1n401 \le n \le 40, k5k \le 5.
  • For 100%100\% of the testdata, 1kn2001 \le k \le n \le 200, 1m2×1051 \le m \le 2 \times 10^5, 1ri,ui1041 \le r_i, u_i \le 10^4, 1q1061 \le q \le 10^6.

Time and Memory Limits

Time limit: 1.00 s, Memory limit: 125.00 MB.

Sample Explanation

As shown in the figure.

样例解释

Translated by ChatGPT 5