2967: Job Hunt
Total Submit: 9 Accepted:7
Description
Bessie is running out of money and is searching for jobs. Farmer John knows this and wants the cows to travel around so he has imposed a rule that his cows can only make D (1 ≤ D ≤ 1,000) dollars in a city before they must work in another city. Bessie can, however, return to a city after working elsewhere for a while and again earn the D dollars maximum in that city. There is no limit on the number of times Bessie can do this.
Bessie's world comprises P (1 ≤ P ≤ 150) one-way paths connecting C (2 ≤ C ≤ 220) cities conveniently numbered 1..C. Bessie is currently in city S (1 ≤ S ≤ C). Path i runs one-way from city Ai to city Bi (1 ≤ Ai ≤ C; 1 ≤ Bi ≤ C) and costs nothing to traverse.
To help Bessie, Farmer John will give her access to his private jet service. This service features F (1 ≤ F ≤ 350) routes, each of which is a one way flight from one city Ji to a another Ki (1 ≤ Ji ≤ C; 1 ≤ Ki ≤ C) and which costs Ti (1 ≤ Ti ≤ 50,000) dollars. Bessie can pay for the tickets from future earnings if she doesn't have the cash on hand.
Bessie can opt to retire whenever and wherever she wants. Given an unlimited amount of time, what is the most money that Bessie can make presuming she can make the full D dollars in each city she can travel to? Print -1 if there is no limit to this amount.
Input
* Line 1: Five space-separated integers: D, P, C, F, and S
* Lines 2..P+1: Line i+1 contains two space-separated integers that name a one-way path from one city to another: Ai and Bi
* Lines P+2..P+F+1: Line P+i+1 contains three space-separated integers that name a one-way jet flight from one city to another and the price for that flight: Ji, Ki, and Ti
Output
* Line 1: A single integer representing the most money she can make while following the law.
Sample Input
100 3 5 2 1
1 5
2 3
1 4
5 2 150
2 5 120
Sample Output
250
Source
分析:带负权回路的单源最短路。
#include
#include
#include
#include
#include
#include
Bessie在有限时间内通过遍历多个城市寻找工作机会,每次可在每个城市赚取固定金额,利用路径和 Farmer John 提供的飞行服务,目标是在遵循规则的情况下赚取最大金额。

2333

被折叠的 条评论
为什么被折叠?



