{"problem":{"name":"Problem A","description":{"content":"","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":30000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"hokudai_hitachi2019_1_a"},"statements":[{"statement_type":"Markdown","content":"## Explanation\n\nThe example operates on a graph with $|V| = 5$ vertices, $|E| = 7$ edges, and $T_{\\text{max}} = 4$ time steps. We now describe the orders which have occured and the movement of the car.\n\n#### Time $t=0$\n\nAt time $t=0$ an order is placed at the shop. This order has ID$= 1$ and should be delivered to vertex $2$. Because your car is currently at vertex one, the order will be automatically transfered into your car. In this way, when your car is at the shop, all orders which have been made at present and before, will automatically be loaded into your car.\n\n#### Time $0$ → $1$\n\nYou choose to move towards vertex `move 2`. You will now move one step towards vertex 2.\n\n#### Time $t=1$\n\nA new order has appeared. It has ID $=2$ and shall be delivered at vertex $5$.\n\n#### Time $1$ → $2$\n\nYou decided to `stay`. You can now stay on the edge where you are.\n\n#### Time $t=2$\n\nA new order has appeared. It has ID $=3$ and shall be delivered at vertex $4$.\n\n#### Time $2$ → $3$\n\nYou decided to move `move 1` back to vertex 1. You are approaching one step towards vertex 1. Doing a U-turn in this way is explicitly allowed.\n\n#### Time $t=3$\n\nNew orders have not occurred. Now that you are at the vertex $1 $ (store), the orders with order ID $2, 3 $ are loaded into your car. In a similar way, whenever you return to the store, all the orders that have already been placed are loaded into your car automatically.\n\n#### Time $3$ → $4$\n\nBeing at vertex 1 you choose `move 5`. You are moving your car one step towards vertex $5$. You arrive at vertex $5$.\n\n#### Time $t=4$\n\nSince you arrived at vertex $5$, the order with order ID $2$ can be delivered.\n\n## Input Example\n\n5 7\n1 2 5\n5 3 4\n2 4 8\n1 5 1\n2 3 3\n4 5 3\n4 3 9\n4\n1\n1 2\n1\n2 5\n1\n3 4\n0\n\n**Note that this input is an example of small size and does not meet the constraints of the contest.**\n\n## Input Format\n\nInput is provided in the following form:\n\n$|V|$ $|E|$\n$u_{1}$ $v_{1}$ $d_{u_{1}, v_{1}}$\n$u_{2}$ $v_{2}$ $d_{u_{2}, v_{2}}$\n:\n$u_{|E|}$ $v_{|E|}$ $d_{u_{|E|}, v_{|E|}}$\n$T_{\\text{max}}$\n$\\mathrm{info}_{0}$\n$\\mathrm{info}_{1}$\n:\n$\\mathrm{info}_{T_{\\text{max}}-1}$\n\n*   In the first line $|V|$ denotes the number of vertices, while $|E|$ denotes the number of edges.\n*   The following $|E|$ lines denote the edges of the graph. In particular, in the $i$th line $u_{i}$ and $v_{i}$ denote the edge connecting $u_{i}$ and $v_{i}$ and $d_{u_{i}, v_{i}}$ the corresponding distance.\n*   The following line denotes the number of steps $T_{\\text{max}}$.\n\nIn the following line, $\\mathrm{info}_t$ is information about the order from the customer that occurs at time $t$. $\\mathrm{info}_t$ is given in the form:\n\n$N_{\\text{new}}$\n$\\mathrm{new_id}_1$ $\\mathrm{dst}_1$\n$\\mathrm{new_id}_2$ $\\mathrm{dst}_2$\n$\\vdots$\n$\\mathrm{new_id}_{N_{\\text{new}}}$ $\\mathrm{dst}_{N_{\\text{new}}}$\n\n*   $N_{\\text{new}}$ represents the number of new orders which appear at time $t$.\n*   The next $N_{\\text{new}}$ lines give the newly generated order information. The $i$\\-th order information indicates that the order ID $\\mathrm{new_{id}}_i$ of the new order, while $\\mathrm{dst}_i$ denotes the vertex to which the customer wishes the order to be delivered.\n*   Note: If $N_{\\text{new}}=0$, there are no new lines.\n\n## Orders, Deliveries, And Constraints:\n\n*   **Orders:** Throughout the contest each order is characterized by three quantities: A unique order ID, a vertex $v \\in V$ indicating the order destination, and the order time $t$ at which the order appeared. For the detailed format see below.\n*   **Order generation:** At each time $0 \\le t \\le T_{\\text{last}} = 0.95 \\times T_{\\text{max}}$ up to one new order can appear with probability $p_{\\text{order}}(t)$. In case there is an order, the order destination $i$ is chosen from the vertex set $V$ with probability proportional to the order frequency $f_i$. For details, see the pseudo-code below or the sample code further below.\n\n**Pseudo code:** Order generation\n\n*   **Input:** Last order time $T_{\\text{last}}$ and average order probability $p_{\\text{order}}(t)$.\n*   **Init:** $\\mathrm{ID} \\leftarrow 0$.\n*   For each step $t = 0, ..., T_{\\text{last}} $ do:\n    *   Generate a uniform random number $r \\in [0,1] $ .\n    *   **If** $r \\le p_{\\text{order}}(t) $ :\n        *   Select a vertex position $u \\in V $ at random with probability proportional to the order frequency $f_{u} $ of the vertex.\n        *   $\\mathrm{ID} \\leftarrow \\mathrm{ID} + 1$\n        *   place order (new order ID, order time $t$, vertex position $u \\in V $ )\n    *   **Else:** place no order\n\n*   **Note:** The average order probability is defined as follows:\n*   $p_{\\text{order}}(t) = \\begin{cases} t / T_{\\text{peak}}, & \\text{if } 0\\le t \\lt T_{\\text{peak}}, \\\\ (T_{\\text{last}} - t) / (T_{\\text{last}}- T_{\\text{peak}}), & \\text{if } T_{\\text{peak}} \\le t \\lt T_{\\text{last}}, \\\\ 0, & \\text{if } T_{\\text{last}} \\le t, \\end{cases}$\n*   where $T_{\\text{last}}:=0.95 \\times T_{\\max}$ and $T_{\\text{peak}}$ is drawn randomly uniform from the interval $[0, T_{\\text{last}}]$.\n*   Note: The value of $T_{\\text{peak}}$ will not be given as an input.\n\n![image](https://img.atcoder.jp/hokudai-hitachi2019-1/caa24f9e6a715e0d1a778f1fdfe4e14b.png)\n\n*   **Delivery:** To deliver an order, the contestant must do the following steps after the order has been placed:\n    *   **(1st) Move the car onto the shop:** Note: When moving a car onto the shop, all orders with order time less than or equal to the current time, will be transfered into the car. On the other hand, orders which have not appeared yet, cannot be placed into the car.\n    *   **(2nd) Move the car to the customer position:** To finalize a delivery, move the car onto the vertex of the customer position. Note: Orders which have not been transfered into the car yet, will not be delivered, even if you arrive at the customer position.\n\n![image](https://img.atcoder.jp/hokudai-hitachi2019-1/03b28647c6ddc92cc3cbb33ade09f468.png)\n\n*   **Constraints:** Throughout the contest, we assume each order has a unique $\\text{ID}$ and should be delivered to the corresponding customer. It is further assumed that an unlimited number of orders can be placed in the car.\n\n## Output Example\n\n2\n-1\n1\n5\n\n[samples]\n\n## Output Format\n\nThe Output expects $T_{\\text{max}}$ integers in the format specified below.\n\n$\\mathrm{command}_{0}$\n$\\mathrm{command}_{1}$\n:\n$\\mathrm{command}_{T_{\\text{max}}-1}$\n\nIn particular, $\\mathrm{command}_{i}$ shall specify the movement of the delivery car by using one of the following two options:\n1) `stay`, if the car shall not move:\n\n\\-1\n\n2) `move w`, if the car shall be moved one step towards the neighboring vertex $w$\n\nw\n\nNote that in case of 2) $w$ has to satisfy the following conditions:\n\n*   $w \\in V$\n*   If the car is at vertex $u$: $\\left{ u, w \\right} \\in E $ .\n*   If the car is on the edge $\\left{ u, v \\right}$, $w$ must either satisfy $u = w$ or $v = w$.\n\n* * *\n\n## Overview\n\n*   **Concept:** In this programming contest, you will run a delivery service. Customers will place orders with your shop. Each order has a unique $\\text{ID}$ and should be delivered to the corresponding customer. Your delivery service has one car. The car will fetch the ordered item from the shop and deliver it to the customer.\n*   **Score:** Your goal is to deliver as many items as possible, as quickly as possible in a given amount of time $T_{\\text{max}}$. (Orders are expected until $0.95 \\times T_{\\text{max}}$).\n*   **Constraint:** In this contest there is no constraint on the number of items you can place in the car. However, an item can only be loaded in the car, by fetching it from the shop, after the order has been placed.\n*   **Problem A/B:** In problem A all order positions and times are given to the contestant in advance and the contestant algorithm shall optimize the moves of the car to make as many deliveries as possible as fast as possible. On the other hand, in problem B orders appear online, that is new orders appear, while you move your car to make as many deliveries as possible as fast as possible.\n\n![image](https://img.atcoder.jp/hokudai-hitachi2019-1/7faf401c00c790b9a8cb5c6968dc80c3.png)\n\n## Particulars Of Problem A\n\nIn problem A we pass all orders which appear at time $0 \\le t < 0.95 \\times T_{\\text{max}} $ as an input to the contestant code. The task is to provide an algorithm which optimizes the moves of the car such that the above score becomes maximal.\n\n* * *\n\n## Requirements\n\n*   All inputs are of non-negative integer value.\n*   $T_{\\text{max}} = 10000$\n*   $200 \\leq |V| \\leq 400$\n*   $1.5 |V| \\leq |E| \\leq 2 |V|$\n*   $1 \\leq u_{i}, v_{i} \\leq |V|$ $(1 \\leq i \\leq |E|)$\n*   $1 \\leq d_{u_i, v_i} \\leq \\lceil 4\\sqrt{2|V|} \\rceil$ $(1 \\leq i \\leq |E|)$\n*   The given graph has no self-loops / multiple edges and is guaranteed to be connected.\n*   $0 \\leq N_{\\text{new}} \\leq 1$\n*   $1 \\leq \\mathrm{new_id}_{i} \\leq T_{\\text{last}}+1$ $(1 \\leq i \\leq N_{\\text{new}})$. Note: If all orders are generated by the order generation rule as explained above, the total number of orders is at most $T_{\\text{last}}+1$. Therefore, the possible range of $\\mathrm{new_id}_{i}$ should be from $1$ to $T_{\\text{last}}+1$.\n*   $2 \\leq \\mathrm{dst}_i \\leq |V|$ $(1 \\leq i \\leq N_{\\text{new}})$\n*   The order IDs $\\mathrm{new_{id}}_i$ are unique.\n\n## Scoring\n\n*   During the contest the total score of a submission is determined by summing the score of the submission with respect to 30 input cases.\n*   After the contest a system test will be performed. To this end, the contestant's **last submission** will be scored by summing the score of the submission on 100 previously unseen input cases.\n*   For each input case, the score is calculated as follows:$\\text{Score} = \\sum_{i \\in D} {(T_{\\text{max}})}^{2} - {(\\mathrm{waitingTime}_i)}^{2},$\n    Here we use the following definitions:\n    *   $D $ : the set of orders delivered until $t=T_{\\text{max}}$\n    *   the waiting time of the $i$th order: $\\mathrm{waitingTime}_i = \\mathrm{deliveredTime}_i - \\mathrm{orderedTime}_i$.\n    *   Note that an input case giving the output `WA` will receive $0$ points.\n\n## Specification Of Car Locations And Moves:\n\nIn order to make deliveries you will operate a delivery car, which can take positions and make moves as specified below.\n\n*   **Car position:** A car can generally take two types of position:\n    *   on a vertex $u \\in V$.\n    *   on an edge $\\left{ u, v \\right} \\in E$. More specifically, it is located at a distance $x$ $(0 \\lt x \\lt d_{u, v})$ from $u $ to $v $ .\n*   **Car move:** At each step $0 \\le t < T_{\\text{max}} $ you have to choose one of the following actions in order to control your delivery car.\n    \n    *   `stay`: stay at the current position.\n    *   `move w`: Take one step towards vertex $w \\in V$.\n    \n    In case of choosing `move w`, $w$ must obey the following constraints. A failure to obey these constraints results in a wrong answer `WA`.\n    \n    *   $w$ must be a vertex, i.e., $w \\in V$.\n    *   If the car is on vertex $u \\in V$, there must be an edge connecting $u$ and $v$, i.e., $\\left{ u, w \\right} \\in E$.\n    *   If the car is on the edge $\\left{ u, v \\right} \\in E$, $w$ must either be $w = u$ or $w = v$.\n    \n\n![image](https://img.atcoder.jp/hokudai-hitachi2019-1/60c6d261238fb10fb2bb26d89d275f9c.png)\n\n## Specification Of Time And Space:\n\n*   **Time:** In this contest we model the progress of time by integer values $0 \\le t < T_{\\text{max}}$.\n*   **Map:** In this contest we model a map by a simple, undirected, and connected graph $G=(V, E)$, consisting of a set of vertices $V$ and a set of edges $E$\n*   **Shop and customer locations:** The vertices $u \\in V$ are labeled from $1$ to $|V|$ and the vertex $u=1$ denotes the location of your shop, while vertices $u = 2,...,|V|$ denote locations of potential customers. Here, $|V|$ denotes the number of elements of the set $V$.\n*   **Streets:** Each edge $\\left{ u, v \\right} \\in E$ represents a street connecting the vertices $u, v \\in V$. The corresponding length is given by an integer edge weight $d_{u, v} \\ge 1$.\n*   **Graph creation:** The algorithm for generating the map graph based on a random seed is specified in the following pseudo-code. For further details, please see the sample code below.\n\n**Pseudo code:** Map graph generator\n\n*   **Input:**$|V|$, $|E|$, $\\mathrm{MaxDegree}=5$\n*   **2d vertex grid:**\n    *   First, find the largest integer $R>0$ such that $|V| = R^{2} + r$, with $r$ being the smallest possible non-negative integer.\n    *   Then we plot points $(x, y)$ on the 2d vertex grid $(0 \\leq x, y \\lt R)$.\n    *   For each point $(x, y)$ add a uniform random offset $dx, dy \\in [0, 1] $ , giving the final vertex position $(x + dx, y + dy)\\in [0,R] \\times [0,R]$.\n    *   Finally, add the remaining $r$ vertices at a uniform random position $(x, y)$ with $0 \\leq x, y \\leq R$.\n    *   Vertex labels $u \\in V$ are assigned by random shuffling. The shop is the vertex $u=1$.\n*   **How we create Highways:**\n    *   To generate a highway network, we create a complete graph $G_{\\text{comp}}$ on the vertex set $u \\in V$, assigning each vertex pair $u, v \\in V \\times V$ the Euclidean distance $W_{u, v}$ as an edge weight.\n    *   Next, we construct a [minimum spanning](https://en.wikipedia.org/wiki/Minimum_spanning_tree) tree of $G_{\\text{comp}}$. The $|V|-1$ edges of the minimum spanning tree are the highway network of the graph $G$. We assign each of those edges $\\left{ u, v \\right}$ an edge weight $d_{u,v} \\leftarrow \\lceil 2 \\times W_{u, v} \\rceil $ .\n*   **How we add side roads:**\n    *   To create a network of side roads, we successively add $|E|-(|V|-1)$ edges to the graph $G$ as follows:\n        *   Update $\\mathrm{cost}(u,v)$.\n        *   Among the vertex pairs $\\left( u, v \\right) \\in V\\times V$, not yet connected by an edge, select a pair with minimal $\\mathrm{cost}(u,v)$.\n        *   Assign the edge weight $d_{u,v} \\leftarrow \\lceil 4 \\times W_{u, v} \\rceil $ .\n    *   Here, $\\mathrm{cost}(u,v)$ is essentially based on the Euclidean distance of vertices, giving preference to connecting nearby vertices with low degree. In addition, preference is given to side roads along the rectangular grid, to avoid too many bridges. The detailed definitions are as follows:\n        *   Define $\\mathrm{degree}(u)$, the degree of vertex $u\\in V$ as the number of incident edges.\n        *   Define $\\mathrm{color}(u)$ for each vertex $u\\in V$ according to its original position $(x,y)$ on the vertex grid as:\n            *   If $x+y$ is even : $\\mathrm{color}(u) = 0$\n            *   If $x+y$ is odd : $\\mathrm{color}(u) = 1$\n            *   For the remaining $r$ vertices : Assign a color $\\mathrm{color}(u) \\in \\left{0,1\\right}$ at random.\n        *   Define a factor $f(u,v)$ as follows:\n            *   If $\\mathrm{color}(u)$ and $\\mathrm{color}(v)$ are the same : Set $\\mathrm{f}(u,v) = 5$\n            *   If $\\mathrm{color}(u)$ and $\\mathrm{color}(v)$ are different : Set $\\mathrm{f}(u,v) = 1$\n        *   Define a factor $g(u)$ as follows:\n            *   If $\\mathrm{degree}(u) \\lt \\mathrm{MaxDegree}$ : Set $g(u)=1$\n            *   If $\\mathrm{degree}(u) \\geq \\mathrm{MaxDegree}$ : Set $g(u)=\\infty$\n        *   Finally, the cost is defined as follows:\n            *   $\\mathrm{cost}(u,v) = W_{u,v}\\times \\mathrm{degree}(u) \\times \\mathrm{degree}(v) \\times f(u,v) \\times g(u) \\times g(v)$.\n*   **How we assign order frequencies:**\n    *   Assign each vertex $u \\in V$ an order frequency $f_u \\in \\left{0,1,2\\right}$.\n    *   Init the order frequency of the shop vertex: $f_1 \\leftarrow 0$.\n    *   Init the order frequency of the other vertices: $f_u \\leftarrow 1$\n    *   Now determine vertices with order frequency 2. For this draw a uniform random center point $c=(c_x,c_y)\\in [R/4,3R/4]\\times[R/4,3R/4]$ and then for all vertices $u=2,...,|V|$ do:\n        *   If $\\mathrm{EuclideanDistance}(c,u)\\le R/8 + \\mathrm{uniformRandom}[0,R/8]$: $f_{u} \\leftarrow 2$","is_translate":false,"language":"English"}],"meta":{"iden":"hokudai_hitachi2019_1_a","tags":[],"sample_group":[],"created_at":"2026-03-03 11:01:13"}}