E Stands for Efficiency
June Square is a young financial company whose goal is to develop a new, efficient, decentralized payment system written entirely in their favourite programming language JavaScri... OCaml! Obviously, the name of their currency would have to be JScoin.
The work started in 2015 when June Square invested in building geographically distributed cryptocurrency storage units with communication lines between them. Since this system is global, each person in the world gets a wallet created in one of these storage units. To transfer a single JScoin between two people, the system finds the shortest path in the communications graph between the storage units holding their respective wallets and transfers JScoin along that path. Moving a single JScoin between two directly connected storage units takes exactly 1 megawatt, thus, transferring a JScoin along a path traversing connections takes exactly megawatts.
To optimise the energy budget, storage units should be built in distant areas with cheap energy. As a result, creating direct connections between them becomes very complicated and expensive. Therefore, the June Square leadership decided to limit the number of direct connections to each storage unit by .
Such limitations mean that the connections had to be designed thoroughly. The analytics department has already predicted the number of JScoins transferred during a year between each pair of storage units. Given that knowledge, design the connections network between the units so that the total predicted energy expenditure over a year will be as small as possible.
Input Data
You are given a zip-archive with tests: 01
, 02
, , 12
.
Download inputs (problem-e-inputs.zip
)
The first line of each test contains three integers: the number of storage units (), the number of JScoin transaction predictions (), and the maximum number of direct connections per unit ().
lines follow. The -th of these lines contains three integers , , (, , ): two storage unit indices and the predicted number of JScoins to transfer between them. No pair of storage units is listed more than once.
Here is a short description of these tests:
Test | |||
---|---|---|---|
01 |
28 | 41 | 3 |
02 |
96 | 256 | 3 |
03 |
96 | 348 | 4 |
04 |
121 | 2322 | 2 |
05 |
100 | 1431 | 3 |
06 |
100 | 4506 | 4 |
07 |
3141 | 314159 | 2 |
08 |
544 | 1620 | 3 |
09 |
1023 | 1023 | 2 |
10 |
10000 | 151677 | 3 |
11 |
10000 | 1000000 | 4 |
12 |
10000 | 1000000 | 3 |
Output Data
You should submit files 01.out
, 02.out
, , 12.out
with answers to corresponding inputs. Some of the files may be missing.
Each of these files should be in the following format:
- The first line should contain the number of direct connections .
- The next lines should contain the connections as the indices of connected storage units, separated by whitespace.
Scoring
If any of the following happens in your output:
- there is a format error;
- there is a storage unit connected to itself;
- two storage units are connected more than once;
- a storage unit has more than connections;
- there is no possibility to pass all required JScoins through the connection graph;
then your output is considered to be incorrect.
Otherwise, let be the shortest distance from unit to unit using the provided connections. The total amount of energy in megawatts (or points) is then computed as follows:
Your final score for the test is calculated as follows:
- If the output is incorrect, it gets points.
- Otherwise, it will be proportional to the cube of the lowest amount of points among all participants for this test divided by the number of points for your output: .
Note that the scoreboard will show your best score for each test among all your submissions.
Problem by Jane Street
