|
||||||||||
Dinner Coming SoonTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Submission(s): 3213 Accepted Submission(s): 622 Problem Description Coach Pang loves his boyfriend Uncle Yang very much. Today is Uncle Yang¨s birthday, Coach Pang wants to have a romantic candlelit dinner at Uncle Yang¨s house and he has to arrive there in T minutes. There are N houses in their city numbered from 1 to N. Coach Pang lives in house 1 while Uncle Yang lives in house N. The houses are connected byM directed roads. It takes some time and usually a fee to pass one road. Coach Pang wants to reach Uncle Yang¨s house before the dinner starts with as much money as possible. But the matter is not so simple. Coach Pang decides to do some salt trade on the way to Uncle Yang¨s house. The host of each house offers a price of a bag of salt, so Coach Pang can make a profit from the price differences. Each time when Coach Pang arrives at a house (except the house 1 and the house N). He can buy one bag of salt, sell one bag of salt or do nothing. Coach Pang can carry at most B bags of salt with him, and he carries no salt when he leaves his house. The trading is so efficient that the time cost of trading can be ignored. However, the problem is more complicated than imagine. Coach Pang has a handheld device that can perform a journey around K parallel universes numbered from 0 to K-1. Coach Pang lives in the universe 0. When Coach Pang uses the device in universe i, he will be transported to the same place and the same time of universe (i+1) modK. The host of the house at the same place in different universe may offer a different price of salt. Luckily, the time cost and fee of the city roads are uniform among the K universes. The journey between universes costs no time but Coach Pang has to stand still watching the ads on the device for one minute every time before the device works. Remember, Coach Pang should never visit house 1 or house N in a universe other than universe 0, because the situation might become uncontrollable if he bumps into himself or his boyfriend in another universe. The time is running out. Coach Pang asks you to tell him whether he can arrive at Uncle Yang¨s house in time, and how much money Coach Pang can have at most when the dinner starts. Coach Pang has R yuan at the start, and will end his journey immediately once he arrives at Uncle Yang¨s house. He must arrive at Uncle Yang¨s house in T minutes, and he can¨t have negative amount of money anywhere anytime. Please help him! Input The first line of the input is an integer C representing the number of test cases. For each test case, the first line will contain 6 integers N, M, B, K, R, T, as described above. (2 <= N <= 100, 0 <= M <= 200, 1 <= B <= 4, 2 <= K <= 5, 0 <= R <= 105, 0 <= T <= 200) The following K lines contain N integers each, indicating the price pij (0 <= i < K, 1 <= j <= N) for a bag of salt offered by the host of house j in the universe i. The price of house 1 and house N will be marked as -1.(1 <= pij <= 100) Then M lines follow, each contains 4 integers a, b, t and m, indicating that there is a road from house a to house b that costs t minutes of time and m yuan of money. (1 <= a,b <= N, a<> b, 1 <= t <=15, 0 <= m <= 100) Output For each test case, output one line containing ^Case #x: y ̄, where x is the case number (starting from 1) and y is the most money Coach Pang can have if he can have dinner with Uncle Yang on time. Print "Forever Alone" otherwise. Sample Input
Sample Output
Source | ||||||||||
|