問題一覧 > 通常問題

No.2739 Time is money

レベル : / AI推定難易度 : 1050 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 82
作問者 : cho435 / テスター : kenken714 ponjuice Nzt3 tassei903
お気に入りにしたユーザー ProblemId : 10843 / 自分の提出
問題文最終更新日: 2024-04-22 02:16:51
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
CPCTF 2024 : PPC (順位表) の他の問題:

Problem Statement

There are $N$ towns connected by $M$ roads.
Using the $i \ (1 \leq i \leq M)$-th road, you can travel in both directions between town $u_i$ and town $v_i$.
Using this road costs a toll of $C_i$ yen, and traveling along it takes $T_i$ hours.
In town $1$ you can work, and you earn $X$ yen for every $1$ hour of work.
Anything other than traveling along roads and working takes $0$ time.

You are currently in town $1$ and have $0$ yen.
When traveling from town $1$ to town $N$ as quickly as possible, what is the minimum number of hours until you reach town $N$?
If it is impossible to travel to town $N$, print -1.

Constraints

  • All input values are integers.
  • $2 \leq N \leq 2 \times 10^5$
  • $1 \leq M \leq 2 \times 10^5$
  • $1 \leq X \leq 2 \times 10^5$
  • $1 \leq u_i, v_i \leq N \ (1 \leq i \leq M)$
  • $1 \leq C_i, T_i \leq 2 \times 10^5 \ (1 \leq i \leq M)$

Input

The input is given from standard input in the following format.

$N \  M \  X$
$u_1\ v_1\ C_1\ T_1$
$u_2\ v_2\ C_2\ T_2$
$\vdots$
$u_M\ v_M\ C_M\ T_M$

Output

If it is impossible to travel from town $1$ to town $N$, print -1.
Otherwise, print the minimum time required to travel to town $N$.

Sample

Sample 1
Input
5 6 10
1 3 7 2
4 1 2 5
3 4 1 3
2 3 5 4
4 5 6 8
2 5 4 1
Output
9

The fastest way is to work for $2$ hours in town $1$ and then travel through town $1$, town $3$, town $2$, town $5$ in this order.

Sample 2
Input
3 3 1
1 1 100 100
3 2 1 1
2 3 1 1
Output
-1

It is impossible to move out of town $1$.

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