2014 Anshan network qualifiers 1010 (point reduction + Gaussian yuan elimination) hdu5006

Source: Internet
Author: User
Resistance Time Limit: 6000/3000 MS (Java/others) memory limit: 65536/65536 K (Java/Others)
Total submission (s): 280 accepted submission (s): 82


Problem descriptionrecently DRD got a number of wires. Some of the wires have the Resistance 1 ohm while the others have the resistance 0 ohm. Each wire has probability 50% to be 0 ohm or 1 ohm.

Now ATM gets a circuit board. there are N points in the circuit board. DRD wants to connect these points using his wires. he chooses a wire randomly and chooses two points in the Board randomly. then he will connect the two points using the wire he chooses. DRD will use M wires. note that it's possible that there exist two points which are not connected by wires.

ATM is interested in the equivalent resistance between the point S and point T. Since they lack of instruments, they want you to calculate the answer.
Inputthe first line contains an integer T, denoting the number of the test cases.

For each test case: the first line contains 4 integers: n, m, S, and T. for each of the next M lines, it contains 3 integers: U, V, and C, representing that DRD uses a wire, whose resistance is C, to connect the point u and v. it's guaranteed that 1 <= n <= 10000 and M = 4 * n. 1 <= u, v <= n. C is randomly chosen from {0, 1} and U and V are randomly chosen from {1, 2 ,..., n }. note that u can equal v.
Outputfor each test case, output a real number. there must be exactly 6 digits after the decimal point. if S and T are not connected by wires, output "inf" (without quotes) instead.
Sample Input
210 40 6 19 4 17 3 110 1 05 2 06 7 17 3 13 5 13 6 18 10 08 3 07 3 13 9 12 8 110 5 010 2 110 9 19 1 07 5 110 2 08 1 02 8 010 2 01 5 05 4 07 4 18 5 14 3 16 1 15 10 03 9 15 1 09 2 13 4 15 8 03 5 13 4 12 7 04 4 01 8 010 10 010 40 2 15 6 18 10 13 8 18 5 06 4 19 9 13 6 12 4 19 8 09 3 07 7 18 6 110 4 11 3 02 8 19 8 08 1 16 4 03 4 01 4 01 10 09 10 06 1 13 1 15 4 01 2 17 2 110 9 06 1 010 3 18 6 11 4 01 1 04 3 01 8 07 10 110 6 04 5 02 2 04 2 1
 
Sample output
0.3333330.222222

Question: RT
Idea: This is actually a high school physics question, and it also makes me drunk
First of all, it is meaningless to set the edges to 0. Therefore, you can merge all vertices whose adjacent edges are 0.
Because the data is random, there will be no more points after all merged points.
Here, the potential of each vertex is set to UI. According to kihof's current law, the current flowing into a vertex is equal to the current flowing out, so for any vertex I, there is a Σ (ui-UJ) /rij = 0, where vertex J is the adjacent contact of I
This formula is available for each vertex, so now it is n unknown and n equations, which can be solved by Gaussian elimination element.
In order to facilitate the solution, an initial current of 1 can be sent to the entire circuit, starting from point S and starting from point T.
Then, at initialization, Σ (US-UJ)/rsj = 1, Σ (UT-UJ)/RTJ =-1, and the other values are set to 0.
Because the current is only related to the electric potential difference, there must be an infinite number of solutions after initialization, and Gaussian element elimination cannot be solved.
To prevent this, we can assume that the potential of one of the nodes (any node) is a constant. Then, the potential of all the nodes is fixed, and the potential of all points must be solved.
Because the initial current is 1, the answer is (US-ut)/1, total resistance = total potential difference/total current

2014 Anshan network qualifiers 1010 (point reduction + Gaussian yuan elimination) hdu5006

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.