Under construction

Still being built. Things may change

Kirchhoff's Laws

Time limit2sMemory limit512 MB

Summary
Given a resistor network, compute the equivalent resistance between node 1 and node N by solving Kirchhoff's laws.
Level

Hard8 of 10

Topics
Graph, Math, Matrix, Implementation
Solved
No attempts yet

Problem

A circuit has NN nodes and MM resistors. A resistor joins two different nodes, and two nodes can be joined by more than one resistor.

Push a current of 1 A into node 1 and draw the same current out of node NN. The potential difference between the two nodes is the total resistance between node 1 and node NN. Read the circuit and compute that total resistance.

Input

The first line has the number of nodes NN and the number of resistors MM. (2<N≤1002 < N \le 100, 1≤M≤3001 \le M \le 300)

Each of the next MM lines describes one resistor as three integers uu, vv, rr, meaning a resistor of value rr joins node uu and node vv. (1≤u,v≤N1 \le u, v \le N, u≠vu \ne v, 1≤r≤1001 \le r \le 100)

Not every node is guaranteed to be connected to node 1. The total resistance between node 1 and node NN is never infinite.

Output

Print the total resistance between node 1 and node NN, rounded at the third decimal place and written with exactly two decimals. When the exact value sits halfway between two candidates, round up. For an exact value of 79.595, print 79.60.

Examples2

  1. Example 1

    Input
    4 5
    1 2 15
    2 4 5
    1 3 10
    3 4 10
    2 3 1
    
    Expected output
    9.40
    
  2. Example 2

    Input
    3 3
    1 2 91
    1 2 109
    2 3 30
    
    Expected output
    79.60