Travel in time

**Time Limit: 8000/4000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)**

Total submission (s): 971 accepted submission (s): 196

Problem description Bob gets tired of playing games, leaves Alice, and travels to Changsha alone. yuelu Mountain, orange Island, window of the world, the Provincial Museum etc... are scenic spots Bob wants to visit. however, his time is very limited,

He can't visit them all.

Assuming that there are n scenic spots in Changsha, Bob defines a satisfaction value Si to each spot. if he visits this spot, his total satisfaction value will plus SI. bob hopes that within the limited time t, he can start at spot S, visit some spots selectively,

And finally stop at spot E, so that the total satisfaction value can be as large as possible. it's obvious that visiting the spot will also cost some time, suppose that it takes CI units of time to visit spot I (0 <= I <n ).

Always remember, Bob can choose to pass by a spot without visiting it (including S and E), maybe he just want to walk shorter distance for saving time.

Bob also has a special need which is that he will only visit the spot whose satisfaction value is

**Strictly**Larger than that of which he visited last time. For example, if he has visited a spot whose satisfaction value is 50, he wo'd only

Visit spot whose satisfaction value is 51 or more then. The paths between the spots are bi-directional, of course.

Input the first line is an integer W, which is the number of testing cases, and the W sets of data are following.

The first line of each test data contains five integers: n m t s e. N represents the number of spots, 1 <n <100; m represents the number of paths, 0 <m <1000; t represents the time limitation, 0 <t <= 300; s means the spot Bob starts from. e Indicates

The end spot. (0 <= s, e <n)

The second line of the test data contains N integers Ci (0 <= CI <= T), which means the cost of time if Bob visits the spot I.

The third line also has n integers, which means the satisfaction value si that can be obtained by visiting the spot I (0 <= SI <100 ).

The next M lines, each line contains three integers u v l, means there is a bi-directional path between spot U and V and it takes L units of time to walk from u to V or from V to U. (0 <= u, v <n, 0 <= L <= T)

Output output case number in the first line (formatted as the sample output ).

The second line contains an integer, which is the greatest satisfaction value.

If Bob can't reach spot e in T units of time, You shoshould output just a "0" (without quotation marks ).

Sample Input

14 4 22 0 31 1 1 15 7 9 120 1 101 3 100 2 102 3 10

Sample output

Case #1:21

Source2013

ACM-ICPC Changsha Division national invitational Competition -- reproduction of questions

Recommendzhoujiaqi2010**Question:**An undirected graph composed of N points and M channels. It takes a certain amount of time to take every path. It takes a certain amount of time to visit the vertices corresponding to each point. Each time you visit an attraction, there will be a satisfaction. Obtain the maximum satisfaction from the start point to the end point within t time. Requirements: 1. the satisfaction of each visited attraction must be greater than that of the previous visited attraction. 2. You can choose to visit each Scenic Spot or just pass.

**Analysis:****1. Because of requirement 1, scenic spots must be sorted in ascending order of satisfaction. If the satisfaction is equal, it is sorted by number.****2. Three-point thinking: first, consider the time and satisfaction from the start point to N points, and then insert other accessible points in the middle to update****Time and satisfaction (the shorter the time, the better ---- the shortest of the shortest path, the higher the satisfaction, the better ). In this way, all****The corresponding time satisfaction of the available path is found. At last, as long as the time from the point to the end plus the time to reach the point is less than or equal****T is OK. (The first consideration is equivalent to accessing the site at, but not passing by another point or passing by only passing by without access)****3. Pay attention to the following points:****(1) The first is weight determination. There may be multiple routes between two points.****(2) The second is the processing of the start and end points. The start point can be accessed or passed. If spfa is used from the start point****The start point is access. If spfa starts from the next node, the start point is pass. Therefore, you need to set a virtual****Start Point.****(3) Use of hash arrays.****4. state transition equation: DP [I] [k] indicates the satisfaction obtained when K reaches the I point.**

DP [I] [k] = max (DP [I] [K], DP [J] [k-A [I]. c-maps [I] [J] + A [I]. v)

**Thoughts:**I know that using the max and Min functions in the algorithm header file saves a lot of time !!

**Code:**

# Include <cstdio> # include <iostream> # include <cstring> # include <algorithm> # define INF 10000000 using namespace STD; int DP [105] [305]; int maps [105] [105]; int hash [105]; typedef struct {int C, V, ID;} Point; point A [105]; // sort bool CMP (point aa, point bb) {If (AA. v! = BB. v) return AA. v <BB. v; return AA. ID <BB. ID;} int main () {int t, n, m, T, S, E, I, J, K, X, Y, Z, ANS, CNT = 1; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & M, & T, & S, & E); for (I = 0; I <n; I ++) {scanf ("% d", & A [I]. c); A [I]. id = I ;}for (I = 0; I <n; I ++) scanf ("% d", & A [I]. v); sort (A, A + N, CMP); for (I = 0; I <n; I ++) hash [A [I]. id] = I; S = hash [s]; E = hash [E]; for (I = 0; I <n; I ++) // initialize the distance between any two points {for (j = 0; j <n; j ++) {// maps [I] [I] = 0; if (I = J) Maps [I] [J] = 0; else maps [I] [J] = inf ;}} for (I = 0; I <m; I ++) {scanf ("% d", & X, & Y, & Z); X = hash [X]; y = hash [y]; maps [x] [Y] = min (z, maps [x] [Y]); maps [y] [x] = min (Z, maps [y] [x]);} For (k = 0; k <n; k ++) // relaxation (spfa update Shortest Path) {for (I = 0; I <n; I ++) {for (j = 0; j <n; j ++) {maps [I] [J] = min (maps [I] [k] + maps [k] [J], maps [I] [J]) ;}} printf ("case # % d: \ n", CNT ++); memset (DP,-1, sizeof (DP); for (I = 0; I <N; I ++) // access the satisfaction level from the virtual start point directly to the I point {fo R (j = A [I]. C + maps [I] [s]; j <= T; j ++) // always enumerate to T. It may pass through other sites but not access DP [I] [J] = A [I]. V ;}for (I = 0; I <n; I ++) {for (j = 0; j <I; j ++) // update {if (a [I]. V = A [J]. v) break; For (k = 0; k <= T; k ++) // The time from enumeration to I is K {If (maps [I] [J] + A [I]. c> K) continue; If (DP [J] [k-maps [I] [J]-A [I]. c] =-1) continue; DP [I] [k] = max (DP [I] [K], DP [J] [k-maps [I] [J]-A [I]. c] + A [I]. v) ;}}ans = 0; for (I = 0; I <n; I ++) {for (j = 0; J + maps [I] [e] <= T; j ++) // virtual endpoint {ans = max (ANS, DP [I] [J]);} printf ("% d \ n", ANS);} return 0;} // AC/609 Ms