You are given an undirected graph with n nodes and m edges.
The nodes are labeled from 0 to n-1.
This graph is guaranteed to be connected and have no self-loops or multiple edges.
You are given a description of the graph: the ints a, b, w, and v.
For each valid i, there is an edge that connects nodes a[i] and b[i] and has weight w[i].
For each valid j, node j has weight v[j].
All weights are positive integers.
A path in this graph is a sequence of pairwise distinct nodes such that each pair of consecutive nodes is connected by an edge.
The difficulty of a path is the value (N times E), where N is the maximum weight of a node on the path (including the nodes where it starts and ends) and E is the maximum weight of an edge on the path.
For each pair of distinct nodes i and j, let d(i,j) be the smallest possible difficulty of a path that connects i and j.
Find and return the sum of d(i,j) with 0 ≤ i < j ≤ n-1.
|Parameters:||int, int, int, int|
|Method signature:||long findMin(int a, int b, int w, int v)|
|(be sure your method is public)|
|-||The values of n and m are not explicitly given. n can be inferred from the length of v and m can be inferred from the length of w.|
|-||n will be between 2 and 300, inclusive.|
|-||m will be between n-1 and min(2,500, n choose 2), inclusive.|
|-||a,b,w will contain exactly m elements.|
|-||It is guaranteed that the graph described by a,b is connected and has no self loops or multiple edges.|
|-||Each element of w will be between 1 and 10^6, inclusive.|
|-||v will contain exactly n elements.|
|-||Each element of v will be between 1 and 10^6, inclusive.|
|There are two nodes and a single edge in this graph. Node 0 has weight 3 and node 1 has weight 6. There is an edge between node 0 and node 1 with weight 5.
In this case we just want to find d(0,1). This is equal to 5*6=30.|
|We have the following values:
|In this case each d(i,j) is 100.
For example, consider d(0,1).
There are two possible paths.
The path 0-1 has maximum node weight 1 and maximum edge weight 100, hence its difficulty is 1*100 = 100.
The path 0-2-1 has maximum node weight 100 and maximum edge weight 1, hence its difficulty is 100*1 = 100 as well.|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.