CF1801D.The way home
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The famous magician Borya Budini traveled through the country X, which consists of n cities. However, an accident happened, and he was robbed in the city number 1. Now Budini will have a hard way home to the city number n.
He's going to get there by plane. In total, there are m flights in the country, i-th flies from city ai to city bi and costs si coins. Note that the i-th flight is one-way, so it can't be used to get from city bi to city ai. To use it, Borya must be in the city ai and have at least si coins (which he will spend on the flight).
After the robbery, he has only p coins left, but he does not despair! Being in the city i, he can organize performances every day, each performance will bring him wi coins.
Help the magician find out if he will be able to get home, and what is the minimum number of performances he will have to organize.
著名魔术师鲍里亚·布迪尼游历了由 n 座城市组成的国家 X。然而,一场意外发生了——他在第 1 号城市遭到了抢劫。如今,布迪尼必须艰难地返回位于第 n 号城市的家。
他将乘坐飞机回家。全国共有 m 班航班,其中第 i 班航班从城市 ai 飞往城市 bi,票价为 si 枚金币。注意:第 i 班航班是单向的,因此无法用于从城市 bi 前往城市 ai。要乘坐该航班,鲍里亚必须身处城市 ai,且身上至少持有 si 枚金币(这些金币将被用于支付机票)。
遭抢劫后,他仅剩下 p 枚金币,但他并未绝望!当他身处城市 i 时,每天都可以举办一场演出,每场演出可为他带来 wi 枚金币。
请帮助这位魔术师判断他是否能够成功回家,并求出他所需举办的最少演出场数。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤80) – the number of test cases. The description of test cases follows.
The first line contains three integers n, m and p (2≤n≤800, 1≤m≤3000, 0≤p≤109) — the number of cities, the number of flights and the initial amount of coins.
The second line contains n integers w1,w2,…,wn (1≤wi≤109) — profit from representations.
The following m lines each contain three integers ai, bi and si (1≤ai,bi≤n, 1≤si≤109) — the starting and ending city, and the cost of i-th flight.
It is guaranteed that the sum of n over all test cases does not exceed 800 and the sum of m over all test cases does not exceed 10000.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤80),表示测试用例的数量。随后是各测试用例的描述。
第一行包含三个整数 n、m 和 p(2≤n≤800,1≤m≤3000,0≤p≤109)——分别表示城市数量、航班数量以及初始金币数量。
第二行包含 n 个整数 w1,w2,…,wn(1≤wi≤109)——表示在各城市举办演出所获得的收益。
接下来的 m 行每行包含三个整数 ai、bi 和 si(1≤ai,bi≤n,1≤si≤109)——分别表示第 i 个航班的出发城市、到达城市以及花费。
保证所有测试用例中 n 的总和不超过 800,且所有测试用例中 m 的总和不超过 10000。
输出格式
For each test case print a single integer — the minimum number of performances Borya will have to organize to get home, or −1 if it is impossible to do this.
对于每个测试用例,输出一个整数——Borya 为回家所需组织的最少演出场次;如果无法回家,则输出 −1。
输入输出样例
输入#1
4 4 4 2 7 4 3 1 1 2 21 3 2 6 1 3 8 2 4 11 4 4 10 1 2 10 1 1 2 20 2 4 30 1 3 25 3 4 89 4 4 7 5 1 6 2 1 2 5 2 3 10 3 4 50 3 4 70 4 1 2 1 1 1 1 1 3 2
输出#1
4 24 10 -1
说明/提示
In the first example, it is optimal for Borya to make 4 performances in the first city, having as a result 2+7⋅4=30 coins, and then walk along the route 1−3−2−4, spending 6+8+11=25 coins. In the second example, it is optimal for Borya to make 15 performances in the first city, fly to 3 city, make 9 performances there, and then go to 4 city.
在第一个例子中,Borya 在第一座城市进行 4 场演出是最优策略,最终获得 2+7⋅4=30 枚金币,然后沿路线 1−3−2−4 行走,花费 6+8+11=25 枚金币。在第二个例子中,Borya 在第一座城市进行 15 场演出,随后飞往第 3 座城市,在那里进行 9 场演出,最后前往第 4 座城市,这是最优策略。
输入解题思路,AI测评打分。不知道怎么写?