This is an optimization problem. The optimal solution for each test is not known to the jury, and your score for each test will be determined as described below.
The Beutsche Dahn (BD) railway network has always been praised for its... unique approach to punctuality. Specifically, every passenger who has ever managed to board a train has eventually reached their destination. But now the future is upon us — the year is $$$1879$$$, and Beutsche Dahn has just been acquired by White Tree Capital (WTC). They intend to use the railroads to relocate their tradesmen to strike urgent deals, so efficiency is extremely important.
As the newly appointed Efficiency Manager for BD at WTC, your job is to manage the entire train fleet according to exact demand. Since you have the complete list of tradesmen and their appearance times at stations in advance, you can precompute a master routing plan to get every tradesman to their destination as fast as humanly possible, while avoiding train collisions (see below).
Formally, you must minimize:
Where:
Now, we will explain how the entire process is emulated and how arrival times are calculated.
The time is split into ticks, starting with tick $$$1$$$. Each tick is processed in the following sequence:
Note on transfers: a tradesman does not have to reach their destination in a single ride. They may be dropped off at an intermediate city and picked up by another train. This can even happen within the same tick, provided that the commands are ordered correctly: the drop action must appear before the corresponding pick action in your output. However, due to travel fatigue, a penalty is incurred when multiple train rides are involved. More specifically:
You are given a zip archive "problem-a-inputs.zip" with $$$8$$$ tests: 01, 02, $$$\ldots$$$, 08.
Each test describes the rail network, the train fleet, and the information about tradesmen. All indices are $$$1$$$-based.
The first line contains two integers $$$V$$$ and $$$E$$$ — the number of cities and undirected rail tracks. Each of the next $$$E$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \leq V, u \neq v$$$) — an undirected rail track between cities numbered $$$u$$$ and $$$v$$$. It is guaranteed that all rail tracks are unique; there is no rail track that goes from a city to itself, and any city is reachable from any other city by following a sequence of rail tracks.
The next line contains an integer $$$T$$$ — the number of trains at your disposal.
The next line contains $$$T$$$ integers between $$$1$$$ and $$$V$$$ — the initial city of each train.
The next line contains an integer $$$C$$$ — the maximum capacity of each train.
The next line contains an integer $$$N$$$ — the total number of tradesmen for the scenario.
Each of the next $$$N$$$ lines contains three integers $$$u_i, v_i, t_i$$$ ($$$1 \le u_i, v_i \leq V$$$, $$$u_i \ne v_i$$$, $$$1 \le t_i \le 10^5$$$) — the starting city, the destination city, and appearance time for the $$$i$$$-th tradesman. Additionally, the tradesmen are ordered by their appearance times: for every $$$i \lt N$$$, it is guaranteed that $$$t_{i} \leq t_{i+1}$$$.
Submit a zip archive with files 01.out, 02.out, $$$\ldots$$$, 08.out. Some of the files may be missing.
Each file should be formatted as follows.
The first line should contain an integer $$$S$$$ — the total number of ticks in your plan. This number should not exceed $$$10^6$$$.
For each tick $$$s = 1, 2, \ldots, S$$$, output should contain the following:
All indices are $$$1$$$-based: $$$1 \le \mathtt{train\_id} \le T$$$, $$$1 \le \mathtt{tradesman\_id} \le N$$$, $$$1 \le \mathtt{city\_id} \le V$$$.
Additionally, to maintain manageable output sizes, the total number of move operations performed, $$$\sum\limits_{s=1}^{S} M_s$$$, must not exceed $$$2 \cdot 10^6$$$. We expect that most solutions would satisfy this restriction without additional optimization.
Your number of points is calculated using the formula
Your final score for the test is calculated as follows:
Note that the scoreboard will consider your best score for each test among all your submissions.
3 2 1 2 2 3 2 1 1 2 3 1 2 1 1 3 1 1 2 1
3 3 pick 1 1 pick 1 2 pick 2 3 1 1 2 1 drop 1 1 2 1 3 2 2 2 drop 1 2 drop 2 3 0
The sample test illustrates the input and output formats. This test is not part of the graded test set.
In this sample, three cities are connected by two rail tracks in a line. There are two trains in city $$$1$$$, each capable of holding $$$2$$$ tradesmen. Three tradesmen appear in city $$$1$$$ at tick $$$1$$$: tradesmen $$$1$$$ and $$$3$$$ need to get to city $$$2$$$, while tradesman $$$2$$$ needs to get to city $$$3$$$.
In the sample output:
Thus, the three tradesmen contribute $$$1$$$, $$$2$$$, and $$$2$$$ to the sum under the square root. Hence, the number of points is
Problem by Alber Blanc
| Name |
|---|


