mvst
Description
The variance of an array is defined as . Here, is the average of the values in . The variance is a measure of dispersion, meaning it measures how far a set of numbers is spread out from their average value.
Hiura is monitoring a communications network. This network consists of devices numbered from to . There are two-way communication channels numbered from to . The -th communication channel connects two distinct devices and with a wavelength , the wavelength used in the communication channel. It is guaranteed that the communication network is connected. In other words, for every pair , devices and are linked (directly or indirectly) by a series of communication channels.
Hiura, surprisingly, loves conformity. Because of this, he wants to pick a spanning tree of the network with the minimum variance. A spanning tree of the network is a subset of the network which includes all the devices, is connected, and contains two-way communication channels.
The variance of a spanning tree is defined as the variance of the wavelengths of its communication channels. In other words, if a spanning tree consists of the communication channels numbered , then the variance of the spanning tree is equal to the variance of the array .
Find the minimum variance over all possible spanning trees of the network.
Implementation Details
You should implement the following procedure.
double solve(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W)
- : The number of devices in the network.
- : The number of communication channels in the network.
- : arrays of integers of length , describing the devices that the communication channels connect and the wavelengths the communication channels have.
- This procedure should return one floating point number containing the minimum possible variance of all possible spanning trees of the network.
- The return value will be considered correct if the absolute difference between the return value of your function and the correct answer is at most .
- This procedure is called exactly once for each test case.
Constraints
- for each such that
- for each such that
- for each such that
- for each such that
- The network is connected
Subtasks
Subtask |
Score |
Additional Constraints |
1 |
|
|
2 |
|
; for each such that |
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
No additional constraints. |
Examples
Consider the following call.
solve(4, 6, [0, 1, 2, 0, 0, 3], [1, 2, 3, 2, 2, 0], [3, 9, 7, 5, 6, 2])
For this example, the minimum variance spanning tree is achieved when we use the -th, -rd, and -th communication channels.
The wavelengths of the communication channels used is .
We can calculate the mean as follows.
After that, we can calculate the variance as follows.
Because the return value is considered correct if the absolute difference is at most one from the correct answer, returning values such as , , or will also be considered correct.
Sample Grader
Input Format:
N M
U[0] V[0] W[0]
U[1] V[1] W[1]
...
U[M - 1] V[M - 1] W[M - 1]
Output Format:
V
Here, is the floating point number returned by solve
.