Potential Graph 1
InterviewTime limit2sMemory limit1024 MB
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.
Problem
Given an undirected simple connected graph with weighted edges. For a function defined on the vertices of , define as follows. Here is the sum over all vertices adjacent to , and is the weight of the edge connecting and . The vertices of are the integers from 1 to . The following three conditions uniquely determine and : (1) . (2) . (3) for every integer with . Given , write a program that prints .
Input
The first line contains the number of vertices and the number of edges of , separated by a space. , From the second line, the next lines each contain three positive integers , , and , separated by spaces. This means there is an edge connecting vertices and with weight . , , Each pair of vertices is connected by at most one edge.
Output
Print the value of . An absolute or relative error of up to is allowed.