CF187B.AlgoRace

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

PMP is getting a warrior. He is practicing a lot, but the results are not acceptable yet. This time instead of programming contests, he decided to compete in a car racing to increase the spirit of victory. He decides to choose a competition that also exhibits algorithmic features.

AlgoRace is a special league of car racing where different teams compete in a country of nn cities. Cities are numbered 11 through nn . Every two distinct cities in the country are connected with one bidirectional road. Each competing team should introduce one driver and a set of cars.

The competition is held in rr rounds. In ii -th round, drivers will start at city sis_{i} and finish at city tit_{i} . Drivers are allowed to change their cars at most kik_{i} times. Changing cars can take place in any city in no time. One car can be used multiple times in one round, but total number of changes should not exceed kik_{i} . Drivers can freely choose their path to destination.

PMP has prepared mm type of purpose-built cars. Beside for PMP’s driving skills, depending on properties of the car and the road, a car traverses each road in each direction in different times.

PMP Warriors wants to devise best strategies of choosing car and roads in each round to maximize the chance of winning the cup. For each round they want to find the minimum time required to finish it.

输入格式

The first line contains three space-separated integers n,m,rn,m,r ( 2<=n<=60,1<=m<=60,1<=r<=1052<=n<=60,1<=m<=60,1<=r<=10^{5} ) — the number of cities, the number of different types of cars and the number of rounds in the competition, correspondingly.

Next mm sets of n×nn×n matrices of integers between 00 to 10610^{6} (inclusive) will follow — describing the time one car requires to traverse different roads. The kk -th integer in jj -th line of the ii -th set is the time that ii -th car requires to traverse the road from jj -th city to kk -th city. These matrices are not necessarily symmetric, but their diagonal is always zero.

Next rr lines contain description of the rounds. The ii -th of these lines contains space-separated integers si,ti,kis_{i},t_{i},k_{i} ( 1<=si,ti<=n,siti,0<=ki<=10001<=s_{i},t_{i}<=n,s_{i}≠t_{i},0<=k_{i}<=1000 ) — the number of starting city, finishing city and the number of possible car changes in ii -th round, correspondingly.

输出格式

For each round you should print the minimum required time to complete the round in a single line.

输入输出样例

  • 输入#1

    4 2 3
    0 1 5 6
    2 0 3 6
    1 3 0 1
    6 6 7 0
    0 3 5 6
    2 0 1 6
    1 3 0 2
    6 6 7 0
    1 4 2
    1 4 1
    1 4 3
    

    输出#1

    3
    4
    3
    
  • 输入#2

    4 2 3
    0 7 3 3
    8 0 10 5
    1 1 0 4
    8 9 2 0
    0 3 3 9
    7 0 4 9
    3 8 0 4
    4 8 9 0
    2 3 3
    2 1 3
    1 2 2
    

    输出#2

    4
    5
    3
    

说明/提示

In the first sample, in all rounds PMP goes from city #1 to city #2, then city #3 and finally city #4. But the sequences of types of the cars he uses are (1, 2, 1) in the first round and (1, 2, 2) in the second round. In the third round, although he can change his car three times, he uses the same strategy as the first round which only needs two car changes.

首页