Under construction

Still being built. Things may change

Potential Graph 1

Interview

Time limit2sMemory limit1024 MB

Summary
Given a weighted connected graph, fix f at 1 for vertex 1 and 0 for vertex N, then find g_f(1) when g_f is zero at every interior vertex.
Level

Medium5 of 10

Topics
Matrix, Graph, Math
Solved
No attempts yet

Problem

Given an undirected simple connected graph G=(V,E)G = (V,E) with weighted edges. For a function f:V→Rf: V \to \mathbb{R} defined on the vertices of GG, define gf:V→Rg_f: V \to \mathbb{R} as follows. gf(u)=∑v:(u,v)∈E(f(u)−f(v))⋅w(u,v)g_f(u) = \sum_{v: (u,v) \in E} (f(u) - f(v)) \cdot w(u,v) Here ∑v:(u,v)∈E\sum_{v: (u,v) \in E} is the sum over all vertices vv adjacent to uu, and w(u,v)=w(v,u)>0w(u,v) = w(v,u) > 0 is the weight of the edge (u,v)∈E(u,v) \in E connecting uu and vv. The vertices of GG are the integers from 1 to NN. The following three conditions uniquely determine ff and gfg_f: (1) f(1)=1f(1) = 1. (2) f(N)=0f(N) = 0. (3) gf(u)=0g_f(u) = 0 for every integer uu with 1<u<N1 < u < N. Given GG, write a program that prints gf(1)g_f(1).

Input

The first line contains the number of vertices NN and the number of edges MM of GG, separated by a space. (2≤N≤100(2 \le N \le 100, N−1≤M≤N(N−1)2)N-1 \le M \le \frac{N(N-1)}{2}) From the second line, the next MM lines each contain three positive integers uu, vv, and ww, separated by spaces. This means there is an edge connecting vertices uu and vv with weight ww. (1≤u,v≤N(1 \le u, v \le N, u≠vu \ne v, 1≤w≤100)1 \le w \le 100) Each pair of vertices is connected by at most one edge.

Output

Print the value of gf(1)g_f(1). An absolute or relative error of up to 10−610^{-6} is allowed.

Examples2

  1. Example 1

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

    Input
    3 3
    1 2 91
    1 3 19
    2 3 30
    
    Expected output
    41.561983