RESIST - Kirchhof Law

no tags 

Input

Multiple test cases. For each test case:

The first line contains integers N and M; N is a number of nodes in the circuit (2 < N <= 100), M is the number of resistors (0 <= M <= 300). Each of the next M lines consists of three integers Ai, Bi and Ri — description of a resistor that has resistance Ri connecting the nodes Ai and Bi (1 <= Ai , Bi <= N; 1 <= Ri <= 100).

There's a blank line between consecutive test cases in the input file. No other extra whitespace will/should be appear in the input/output.

Input terminates by EOF.

Output

For each test case, output the total resistance between the nodes 1 and N rounded within two digits after a decimal points. There won't be any test case the output for which is +INF.

Example

Input:
4 5
1 2 15
2 4 5
1 3 10
3 4 10
2 3 1

Output:
9.40

hide comments
:D: 2016-11-13 18:07:59

I had a lot of trouble with float precision. Doesn't seems to be a issue with the I/O data itself. Just be careful with floating point operations and try to limit the potential computation rounding errors.


Added by:Fudan University Problem Setters
Date:2008-02-05
Time limit:0.5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL GOSU JS-RHINO
Resource:Timus Online Judge, test data by g201513