問題一覧 > 通常問題

No.2387 Yokan Factory

レベル : / AI推定難易度 : 1275 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 138
作問者 : cleantted / テスター : tatyam PCTprobability Mizar 👑 amentorimaru
お気に入りにしたユーザー ProblemId : 9739 / 自分の提出
問題文最終更新日: 2023-07-19 02:09:31
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 398 (順位表) の他の問題:

Problem Statement

You own a yokan factory that produces yokan of various sizes.


Besides the factory, there are $N$ yokan warehouses, and yokan is transported via these warehouses. The warehouses are connected by $M$ bidirectional roads.

Road $i\ (1 \le i \le M)$ connects warehouse $u_i$ and warehouse $v_i$, and traveling along it takes time $a_i$. The width of the road is $b_i$.

For quality control reasons, yokan cannot be transported if the total travel time exceeds $X$. Also, yokan whose size exceeds the width of a road passed through during transport cannot be transported.


You are planning to make yokan that can be transported from warehouse $1$ to warehouse $N$. You would like the transportable yokan to be as large as possible.

Find the maximum size of yokan that can be carried from warehouse $1$ to warehouse $N$ such that the total travel time during transport does not exceed $X$.

Input

$N\ M\ X$
$u_1\ v_1\ a_1\ b_1$
$\vdots$
$u_M\ v_M\ a_M\ b_M$

  • All inputs are integers.
  • $2 \le N \le 10^5$
  • $1 \le M \le 10^5$
  • $1 \le X \le 10^{18}$
  • $1 \le u_i, v_i \le N$
  • $1 \le a_i, b_i \le 10^9$
  • For all $1 \le i \le N$, $u_i \ne v_i$
  • All warehouses are connected.

Output

Output the maximum size of yokan that can be carried within the specified time.

If yokan cannot be transported within the specified time, output -1.

Sample

Sample 1
Input
4 4 6
1 2 2 5
1 3 3 2
2 4 6 4
3 4 2 3
Output
2

The ways to carry yokan from factory $1$ to factory $4$ are either $1→2→4$ or $1→3→4$.

With $1→2→4$, yokan of size up to $4$ can be carried, and with $1→3→4$, yokan of size up to $2$ can be carried.

However, with the route $1→2→4$, the total travel time would be $8$, so yokan cannot be carried along this route. On the other hand, with $1→3→4$, the total travel time is $5$, so yokan can be carried this way.

Therefore, the answer is $2$, the maximum size of yokan that can be carried along $1→3→4$.

Sample 2
Input
3 4 6
1 2 2 5
1 2 3 2
2 3 6 4
2 3 2 3
Output
3

There may be multiple roads between the same pair of factories.

Sample 3
Input
3 2 10
1 2 7 5
2 3 7 5
Output
-1

Since yokan of no size can be carried within the specified time, output -1.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。