A - Problem A Editorial /

Time Limit: 30 sec / Memory Limit: 1024 MB

問題概要

  • 問題のねらい: 本プログラミングコンテストは、買い物支援(配達)サービスの最適化をテーマとしている。本サービスを利用する顧客はそれぞれ異なる品物をお店に注文する(顧客からの注文には固有の\text{ID}が割り振られる)。お店が利用できる車は一台のため、配達中に注文された商品については、お店に戻ってその商品を車に積んでから、顧客のもと商品を届けなければならない。
  • 得点: 最適化の目的は、制限時間 T_{\max} の間に「できるだけ多くの」商品を「できるだけ早く」顧客に届けることである。なお、注文は時刻 0 から時刻 0.95 \times T_{\max} の間に発生する可能性がある。
  • 諸制約: 本コンテストでは、車に積むことのできる商品の数に制限はない。ただし、ある注文に対応する商品をお店まで取りに行き、車に積めるのは、その商品が注文された以降の時刻に限る ことに注意せよ。
  • 問題 A: この問題においては、注文が発生する時刻及び、注文がどの頂点で発生したかなど、注文に関する情報が事前に与えられる。
  • 問題 B: この問題においては、事前に注文に関する情報は与えられず、全ての注文は配達中にオンラインで発生する。

時間・空間について

  • 時間: t0 \leq t < T_{\max} を満たす整数時刻であるとし、各 t において、あなたは時刻 t から t+1 にかけての行動を決定しなければならない。
  • 空間: 単純かつ無向であるグラフ G = (V, E) を考える。ここで V は頂点集合、E は辺集合である。車の移動・注文の発生はすべて、このグラフ内で起こるものとする。
  • 店および顧客の位置: それぞれの頂点 u \in V1 から |V| までで番号付けられている。頂点 u = 1 は店がある頂点であるとし、u = 2, \dots, |V| は顧客がいる頂点であるとする。
  • 道路: それぞれの辺 \left\{ u, v \right\} は、頂点 u と頂点 v を直接結ぶ道路であるとする。辺には整数距離が定められており、これを d_{u, v} \geq 1 と表記する。
  • グラフの生成方法: 地図を表すグラフは、後述のアルゴリズムによってランダムに生成される。
グラフ G の生成について すべてのテストケースにおいて、与えられるグラフ G = (V, E) は以下のアルゴリズムによって生成される。
  • 入力:|V|, |E|, \mathrm{MaxDegree}=5(最大次数)
  • 頂点(店舗+顧客)の生成方法:
    • はじめに、|V| = R^{2} + r を満たす最大の非負整数R を見つける(ただし、r も非負整数とする)。
    • 次に、0 \leq x, y < R を満たすxy座標平面上の全ての格子点に対して、点 (x, y) をプロットする。
    • 各点の座標を (x, y) \leftarrow (x + dx, y + dy) とずらす。ここで dx, dydx, dy \in [0, 1] を満たす一様ランダムな実数である。つまり、移動後の座標は(x + dx, y + dy)\in [0,R] \times [0,R]を満たす。
    • 残りの r 個の点それぞれについて、座標 (x', y') (0 \leq x', y' \leq R の一様ランダムな実数) を定めてプロットする。
    • 各点に対して、1から|V|までの番号をランダムに割り振る。番号1を割り振られた頂点を店舗とする。
  • 高速道路の作成方法:
    • 頂点間をつなぐ道路のうち、まず高速道路を作成する。生成した頂点集合 u \in V に対して、完全グラフ G_{\text{comp}} を生成する。各頂点ペア u, v \in V \times V に対する頂点間のユークリッド距離を、完全グラフにおける辺の重み W_{u, v} と定める。
    • 次に、完全グラフ G_{\text{comp}} に対して、最小全域木 を生成する。最小全域木の |V|-1 本の辺がグラフ G の高速道路網となる。これらの辺の重み d_{u,v}d_{u,v} \leftarrow \lceil 2 \times W_{u, v} \rceil と定める。
  • 残りの道路の作成方法:
    • (高速道路以外の)残りの |E|-(|V|-1) 本の道路は、次の手順で1本ずつ生成される。
      • \mathrm{cost}(u,v)を更新する。
      • グラフGの辺でつながっていないu, vのペアの内、\mathrm{cost(u,v)}の最小を与えるペアをつなぐ辺\left\{ u, v \right\}をグラフGに加える。
      • 選ばれた辺の重み d_{u,v}d_{u,v} \leftarrow \lceil 4 \times W_{u, v} \rceil と定める。
    • ここで \mathrm{cost}(u,v) のベースは頂点間のユークリッド距離だが、低い次数の頂点が選ばれやすくなるように、また、できる限り道の交差を避けるため、斜め方向よりも縦横方向の道が選ばれやすくなるように \mathrm{cost}(u,v) を定める。以下に \mathrm{cost}(u,v) の計算方法の詳細を示す。
      • 各頂点 u\in V の次数 \mathrm{degree}(u) を計算する。次数 \mathrm{degree}(u)u\in V をいずれかの端点に含むグラフ G の辺の本数である。
      • 各頂点 u\in V の色を、頂点の初めの(ずらす前の)座標 (x,y) をもとに、下記のように定める。まずは |V| 個の頂点のうち、R^{2} 個の頂点に対し、
        • x+y が偶数の場合 : \mathrm{color}(u) = 0
        • x+y が奇数の場合 : \mathrm{color}(u) = 1
        • と定める。残りの r 個の頂点には、ランダムに0もしくは1の色を割り当てる。
      • ファクター f(u,v) を以下のように定める:
        • \mathrm{color}(u)\mathrm{color}(v) が同じ場合: \mathrm{f}(u,v) = 5
        • \mathrm{color}(u)\mathrm{color}(v) が異なる場合: \mathrm{f}(u,v) = 1
      • ファクター g(u) を以下のように定める:
        • \mathrm{degree}(u) \lt \mathrm{MaxDegree} の場合: g(u)=1
        • \mathrm{degree}(u) \geq \mathrm{MaxDegree} の場合: g(u)=\infty
      • \mathrm{cost}(u,v) を以下のように計算する。:
        • \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).
  • 各顧客の注文頻度の決定方法:
    • まず、各頂点 u \in V に注文頻度 f_u \in \left\{0,1,2\right\} を割り当てる。
    • 店舗の注文頻度を0に初期化する: f_1 \leftarrow 0.
    • 顧客の注文頻度を1に初期化する: f_u \leftarrow 1
    • 以下、注文頻度2の顧客を定める。そのためにまず、座標平面上の [R/4,3R/4]\times[R/4,3R/4] の領域内に一様ランダムに1点、中心点 c=(c_x,c_y) をプロットする(c=(c_x,c_y)\in [R/4,3R/4]\times[R/4,3R/4])。次に全ての顧客 u=2,...,|V| に対して以下の処理を行う:
      • \mathrm{EuclideanDistance}(c,u)\le R/8 + \mathrm{uniformRandom}[0,R/8] の場合、 f_{u} \leftarrow 2 とする。

車の位置と移動について

配達には車を利用する必要がある。車の位置は次に示すように二種類に分類される。

  • 車の位置: 以下の二種類に分類される。
    • 頂点 u \in V 上にいる場合
    • \left\{ u, v \right\} 上にいる場合。より具体的に言えば、u から v の方向に x (0 < x < d_{u, v}) だけ離れている場合である

また、毎時刻 t において、あなたは以下に示すとおりに車を操作できる。

  • 車の移動: あなたが取れる行動は以下の二種類である。

    • stay: 移動せずその場にとどまる
    • move w: w \in V の方向に向かって距離 1 だけ進む

    move w を選択するとき、w は以下の条件を満たさなければならない。これらの条件を満たさない場合は WA (Wrong Answer) となることに注意せよ。

    • ww \in V を満たす頂点である
    • 車が頂点 u \in V 上にいる場合、頂点対 \left\{ u, w \right\} がグラフの辺集合に含まれていなければならない。すなわち、\left\{ u, w \right\} \in E でなければならない
    • 車が辺 \left\{ u, v \right\} 上にいる場合、w = u または w = v でなければならない

注文・配達等について

  • 注文: それぞれの注文は「注文 ID」「配達先 v \in V」「注文が発生した時刻 t」の三種類の情報を持つ。詳しくは、後述の入力フォーマットを参照のこと。
  • 注文発生について: 顧客からの新しい注文は、0 \leq t \leq T_{\mathrm{last}} = 0.95 \times T_{\max} を満たす時刻 t において確率 p_{\mathrm{order}}(t) で発生する。それぞれの頂点には注文頻度 f_i が定められており、注文が発生するときにその配送先が頂点 i となる確率は \frac{f_i}{\sum_{k} f_k} である。詳しくは以下の疑似コードまたはサンプルコードを参考のこと。

注文発生について
  • 入力: 注文が発生しうる時刻の最大値 T_{\mathrm{last}} と、時刻ごとの注文発生確率を表す関数 p_{\mathrm{order}}(t).
  • 初期化: \mathrm{ID} \leftarrow 0
  • 各時間ステップ t = 0, ..., T_{\mathrm{last}} で以下を実行する:
    • 実数 r \in \left[ 0,1 \right] を一様ランダムに生成する
    • r \le p_{\mathrm{order}}(t) の場合:
      • 1つの頂点 u (u \in V, u \neq 1) を、それぞれの頂点に割り当てられた頻度 f_{u} で重み付けをしてランダムに選択する
      • \mathrm{ID} \leftarrow \mathrm{ID} + 1
      • 注文を発生させる。ここで注文は(注文ID, 注文時間 t, (お届け先の)頂点番号 u \in V)を含む。
    • 上記以外 ( r \gt p_{\mathrm{order}}(t)) の場合: 注文は発生しない
  • 時刻ごとの注文発生確率を表す関数 p_{\mathrm{order}}(t) を下記のように定める:
  • 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}
  • ここで T_{\text{last}}:=0.95 \times T_{\max} であり、 T_{\text{peak}} は区間 [0, T_{\text{last}}] から一様ランダムに定める
  • 注意: T_{\text{peak}} の値は、入力では与えられない。

  • 配達: 注文を受けて、それに対応する商品を顧客まで配達するためには、注文が発生した後に次に示す手順を踏む必要がある。
    1. 車を店まで移動させる: 車が店まで到達すると、現在時刻を同じかそれより前に発生した注文について、それに対応する商品をすべて車に積むことができる。将来にやってくる注文に関して、商品を車に積むことができないことに注意せよ。
    2. 車を顧客がいる場所まで移動させる: 配達を完了させるためには、顧客がいる頂点まで車を移動させる必要がある。ここで、その顧客の注文に対応する商品が車に積まれていない場合は、たとえ顧客がいる頂点まで車を移動させたとしても配達が完了しないことに注意せよ。
  • 注意すべき制約: 注文 ID は注文を識別するためのものであり、互いに異なる整数が割り当てられる。また、一度に車に積むことのできる商品の数には上限がないことに注意されたい。

採点方法

  • 各テストケースの得点の合計がその解答プログラムの得点となる。コンテスト中には 30 個のテストケースが存在する。
  • コンテスト終了後に 100 個の(コンテスト中とは異なる)テストケースに対してシステムテストを行い、その得点を最終得点とする。
  • 各テストケースについて、以下のように得点(Score)を計算する。

    \text{Score} = \sum_{i \in D} {(T_{\max})}^{2} - {(\mathrm{waitingTime}_i)}^{2},

    ここで、
    • D は、時刻 t=T_{\max} までに配達を完了した注文の集合である。
    • i 番目の注文の待ち時間: \mathrm{waitingTime}_i = \mathrm{deliveredTime}_i - \mathrm{orderedTime}_i.
    • WA(不正解)となったテストケースが存在した場合、そのケースの得点は 0 点になる。

問題文 A

問題 A では、顧客からの注文がどの時刻にどこの頂点で発生するかが事前に与えられる。 得点(Score)を最大化するように車を動かすアルゴリズムを作ることが問題Aのタスクである。 ただし商品は、顧客からの注文が発生した後に、車に積む必要がある。(商品の配達の手順を参照せよ) この問題において、時刻 t (0 \leq t \lt T_{\max}) で発生する顧客からの注文は、時刻 t におけるあなたの行動を決定する 直前に 受けとるものとする。


入力

入力は以下の形式で与えられる。

|V| |E|
u_{1} v_{1} d_{u_{1}, v_{1}}
u_{2} v_{2} d_{u_{2}, v_{2}}
:
u_{|E|} v_{|E|} d_{u_{|E|}, v_{|E|}}
T_{\max}
\mathrm{info}_{0}
\mathrm{info}_{1}
:
\mathrm{info}_{T_{\max}-1}
  • 1 行目の |V| はグラフの頂点数、|E| はグラフの辺数を表す。
  • 続く |E| 行で、グラフの辺が与えられる。 |E| 行のうち i 行目は、頂点 u_{i}v_{i} の間に距離 d_{u_{i}, v_{i}} の辺が存在することを表す。
  • 続く 1 行で、あなたが行動する時間の最大値 T_{\max} が与えられる。

続く行のうち \mathrm{info}_t は、時刻 t で発生する顧客からの注文の情報である。 \mathrm{info}_t は以下の形式で与えられる。

N_{\text{new}}
\mathrm{new\_id}_1 \mathrm{dst}_1
\mathrm{new\_id}_2 \mathrm{dst}_2
\vdots
\mathrm{new\_id}_{N_{\text{new}}} \mathrm{dst}_{N_{\text{new}}}
  • N_{\text{new}} は、その時刻において新たに発生した注文の数を表す。
  • 続く N_{\text{new}} 行で、新たに発生した注文情報が与えられる。i 番目に与えられる注文情報は、注文 ID が \mathrm{new\_{id}}_i であり、その注文の発生元 (お届け先) が頂点 \mathrm{dst}_i であることを表す。

制約

  • 入力で与えられる数値は全て整数である
  • T_{\max} = 10000
  • 200 \leq |V| \leq 400
  • 1.5 |V| \leq |E| \leq 2 |V|
  • 1 \leq u_{i}, v_{i} \leq |V| (1 \leq i \leq |E|)
  • 1 \leq d_{u_i, v_i} \leq \lceil 4\sqrt{2|V|} \rceil (1 \leq i \leq |E|)
  • 与えられるグラフは自己ループ・多重辺が存在せず、連結であることが保証される。
  • 0 \leq N_{\text{new}} \leq 1
  • 1 \leq \mathrm{new\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{new}})
    • 注意: 上で説明されたルールに従って注文が生成されたとき、発生する注文の件数の最大値は T_{\text{last}} + 1 となる。ゆえに、\mathrm{new\_id}_{i} の取りうる値は 1 から T_{\text{last}} + 1 までの整数である。
  • 2 \leq \mathrm{dst}_i \leq |V| (1 \leq i \leq N_{\text{new}})
  • 入力全体を通して、与えられる \mathrm{new\_{id}}_i はそれぞれ相異なる整数である。

出力

以下の形式で標準出力に T_{\max} 行の整数を出力せよ。

\mathrm{command}_{0}
\mathrm{command}_{1}
:
\mathrm{command}_{T_{\max}-1}

ただし、\mathrm{command}_{i} は以下のいずれかである。

stay: 車が動かない場合

-1

車の位置は変わらない。

move w: 車を 頂点 w へ向けて 1 メートルすすめる場合

w

ただし、車を動かす場合(move w)、出力は以下の条件を満たす必要がある。条件に違反している場合は WA (不正解) となる。

  • w \in V
  • 車が頂点 u 上にいる場合、\left\{ u, w \right\} \in E が成り立つ。
  • 車が辺 \left\{ u, v \right\} 上にいる場合、u = w または v = w が成り立つ。

入力例

5 7
1 2 5
5 3 4
2 4 8
1 5 1
2 3 3
4 5 3
4 3 9
4
1
1 2
1
2 5
1
3 4
0

この入力は例示用の小さいサイズのものであり、制約を満たさないことに注意せよ

出力例

2
-1
1
5

入出力例の説明

以下の例は、|V| = 5, |E| = 7, T_{\max} = 4 の場合である。 以下に時刻ごとに、発生した注文と車の動きについて、順を追って説明する。

時刻 0

時刻 0 では 1 つの注文が発生しており、その注文の情報は (注文 ID = 1, お届け先 = 2) である。 あなたは今、頂点 1 (店舗)にいるので、注文 1 に対応する商品を車に積む。 このように、注文が発生した時にすでに店舗にいた場合、それに対応する商品を即時に車に積むことができる。

時刻 01

move 2 を選択した。 時刻 0 から 1 の間に、「頂点 2 に向かって 1 メートル進む」ことを表している。

時刻 1

新たに (注文 ID =2, お届け先 =5) という注文が発生している。

時刻 12

stay を選択した。 頂点上、辺上いずれであってもその場にとどまることができる。

時刻 2

新たに (注文 ID =3, お届け先 =4) という注文が発生している。

時刻 23

move 1 を選択した。 頂点 1 に向かって、1 メートル進むことを表す。 このように、来た道を U ターンすることは可能である。

時刻 3

新たな注文は何も発生していない。 あなたは今、頂点 1 (店舗)にいるので、注文 2, 3 に対応する商品を車に積む。 このように、店舗にいる場合、すでに発生している注文のうち、まだ車に積んでいない商品をすべて積む。

時刻 34

頂点 1 上で move 5 を選択した。 頂点 5 に向かって 1 メートル進んだ。

時刻 4

注文 ID 2 のお届け先は 5 であり、対応する商品が車に存在するので、注文 ID 2 の配達が完了した。

サンプルコード A

この問題について、以下のツールキット一式はここからダウンロードできる。

  • 入力サンプルジェネレータ
  • テスター
  • ビキナー向けのサンプルコード

また、ビシュアライザもここにご用意しております。

Problem Setting

Overview

  • 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.
  • 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}}).
  • 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.
  • 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.
overview

Specification of Time and Space:

  • Time: In this contest we model the progress of time by integer values 0 \le t < T_{\text{max}}.
  • 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
  • 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.
  • 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.
  • 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.
Pseudo code: Map graph generator
  • Input:|V|, |E|, \mathrm{MaxDegree}=5
  • 2d vertex grid:
    • First, find the largest integer R>0 such that |V| = R^{2} + r, with r being the smallest possible non-negative integer.
    • Then we plot points (x, y) on the 2d vertex grid (0 \leq x, y \lt R).
    • 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].
    • Finally, add the remaining r vertices at a uniform random position (x, y) with 0 \leq x, y \leq R.
    • Vertex labels u \in V are assigned by random shuffling. The shop is the vertex u=1.
  • How we create Highways:
    • 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.
    • Next, we construct a minimum spanning 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 .
  • How we add side roads:
    • To create a network of side roads, we successively add |E|-(|V|-1) edges to the graph G as follows:
      • Update \mathrm{cost}(u,v).
      • 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).
      • Assign the edge weight d_{u,v} \leftarrow \lceil 4 \times W_{u, v} \rceil .
    • 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:
      • Define \mathrm{degree}(u), the degree of vertex u\in V as the number of incident edges.
      • Define \mathrm{color}(u) for each vertex u\in V according to its original position (x,y) on the vertex grid as:
        • If x+y is even : \mathrm{color}(u) = 0
        • If x+y is odd : \mathrm{color}(u) = 1
        • For the remaining r vertices : Assign a color \mathrm{color}(u) \in \left\{0,1\right\} at random.
      • Define a factor f(u,v) as follows:
        • If \mathrm{color}(u) and \mathrm{color}(v) are the same : Set \mathrm{f}(u,v) = 5
        • If \mathrm{color}(u) and \mathrm{color}(v) are different : Set \mathrm{f}(u,v) = 1
      • Define a factor g(u) as follows:
        • If \mathrm{degree}(u) \lt \mathrm{MaxDegree} : Set g(u)=1
        • If \mathrm{degree}(u) \geq \mathrm{MaxDegree} : Set g(u)=\infty
      • Finally, the cost is defined as follows:
        • \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).
  • How we assign order frequencies:
    • Assign each vertex u \in V an order frequency f_u \in \left\{0,1,2\right\}.
    • Init the order frequency of the shop vertex: f_1 \leftarrow 0.
    • Init the order frequency of the other vertices: f_u \leftarrow 1
    • 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:
      • If \mathrm{EuclideanDistance}(c,u)\le R/8 + \mathrm{uniformRandom}[0,R/8]: f_{u} \leftarrow 2

Specification of Car Locations and Moves:

In order to make deliveries you will operate a delivery car, which can take positions and make moves as specified below.

  • Car position: A car can generally take two types of position:

    • on a vertex u \in V.
    • 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 .
  • 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.

    • stay: stay at the current position.
    • move w: Take one step towards vertex w \in V.

    In case of choosing move w, w must obey the following constraints. A failure to obey these constraints results in a wrong answer WA.

    • w must be a vertex, i.e., w \in V.
    • 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.
    • If the car is on the edge \left\{ u, v \right\} \in E, w must either be w = u or w = v.

Car position and moves

Orders, Deliveries, and Constraints:

  • 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.
  • 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.
Pseudo code: Order generation
  • Input: Last order time T_{\text{last}} and average order probability p_{\text{order}}(t).
  • Init: \mathrm{ID} \leftarrow 0.
  • For each step t = 0, ..., T_{\text{last}} do:
    • Generate a uniform random number r \in [0,1] .
    • If r \le p_{\text{order}}(t) :
      • Select a vertex position u \in V at random with probability proportional to the order frequency f_{u} of the vertex.
      • \mathrm{ID} \leftarrow \mathrm{ID} + 1
      • place order (new order ID, order time t, vertex position u \in V )
    • Else: place no order
  • Note: The average order probability is defined as follows:
  • 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}
  • where T_{\text{last}}:=0.95 \times T_{\max} and T_{\text{peak}} is drawn randomly uniform from the interval [0, T_{\text{last}}].
  • Note: The value of T_{\text{peak}} will not be given as an input.
  • Delivery: To deliver an order, the contestant must do the following steps after the order has been placed:
    • (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.
    • (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.
constraint image
  • 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.

Scoring

  • During the contest the total score of a submission is determined by summing the score of the submission with respect to 30 input cases.
  • 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.
  • For each input case, the score is calculated as follows:

    \text{Score} = \sum_{i \in D} {(T_{\text{max}})}^{2} - {(\mathrm{waitingTime}_i)}^{2},

    Here we use the following definitions:
    • D : the set of orders delivered until t=T_{\text{max}}
    • the waiting time of the ith order: \mathrm{waitingTime}_i = \mathrm{deliveredTime}_i - \mathrm{orderedTime}_i.
    • Note that an input case giving the output WA will receive 0 points.

Particulars of Problem A

In 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.


Input Format

Input is provided in the following form:

|V| |E|
u_{1} v_{1} d_{u_{1}, v_{1}}
u_{2} v_{2} d_{u_{2}, v_{2}}
:
u_{|E|} v_{|E|} d_{u_{|E|}, v_{|E|}}
T_{\text{max}}
\mathrm{info}_{0}
\mathrm{info}_{1}
:
\mathrm{info}_{T_{\text{max}}-1}
  • In the first line |V| denotes the number of vertices, while |E| denotes the number of edges.
  • The following |E| lines denote the edges of the graph. In particular, in the ith line u_{i} and v_{i} denote the edge connecting u_{i} and v_{i} and d_{u_{i}, v_{i}} the corresponding distance.
  • The following line denotes the number of steps T_{\text{max}}.

In 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_{\text{new}}
\mathrm{new\_id}_1 \mathrm{dst}_1
\mathrm{new\_id}_2 \mathrm{dst}_2
\vdots
\mathrm{new\_id}_{N_{\text{new}}} \mathrm{dst}_{N_{\text{new}}}
  • N_{\text{new}} represents the number of new orders which appear at time t.
  • 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.
  • Note: If N_{\text{new}}=0, there are no new lines.

Requirements

  • All inputs are of non-negative integer value.
  • T_{\text{max}} = 10000
  • 200 \leq |V| \leq 400
  • 1.5 |V| \leq |E| \leq 2 |V|
  • 1 \leq u_{i}, v_{i} \leq |V| (1 \leq i \leq |E|)
  • 1 \leq d_{u_i, v_i} \leq \lceil 4\sqrt{2|V|} \rceil (1 \leq i \leq |E|)
  • The given graph has no self-loops / multiple edges and is guaranteed to be connected.
  • 0 \leq N_{\text{new}} \leq 1
  • 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.
  • 2 \leq \mathrm{dst}_i \leq |V| (1 \leq i \leq N_{\text{new}})
  • The order IDs \mathrm{new\_{id}}_i are unique.

Output Format

The Output expects T_{\text{max}} integers in the format specified below.

\mathrm{command}_{0}
\mathrm{command}_{1}
:
\mathrm{command}_{T_{\text{max}}-1}

In particular, \mathrm{command}_{i} shall specify the movement of the delivery car by using one of the following two options:

1) stay, if the car shall not move:

-1

2) move w, if the car shall be moved one step towards the neighboring vertex w

w

Note that in case of 2) w has to satisfy the following conditions:

  • w \in V
  • If the car is at vertex u: \left\{ u, w \right\} \in E .
  • If the car is on the edge \left\{ u, v \right\}, w must either satisfy u = w or v = w.

Input Example

5 7
1 2 5
5 3 4
2 4 8
1 5 1
2 3 3
4 5 3
4 3 9
4
1
1 2
1
2 5
1
3 4
0

Note that this input is an example of small size and does not meet the constraints of the contest.

Output Example

2
-1
1
5

Explanation

The 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.

Time t=0

At 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.

Time 01

You choose to move towards vertex move 2. You will now move one step towards vertex 2.

Time t=1

A new order has appeared. It has ID =2 and shall be delivered at vertex 5.

Time 12

You decided to stay. You can now stay on the edge where you are.

Time t=2

A new order has appeared. It has ID =3 and shall be delivered at vertex 4.

Time 23

You 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.

Time t=3

New 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.

Time 34

Being at vertex 1 you choose move 5. You are moving your car one step towards vertex 5. You arrive at vertex 5.

Time t=4

Since you arrived at vertex 5, the order with order ID 2 can be delivered.

Sample Code A

A software toolkit for generation of input samples, scoring and testing on a local contestant environment, and sample codes for beginners is provided through the following link. In addition we provide software for visualizing the contestants results.

ビジュアライザ

Step
FPS
Command
Δ
Score