Sicily 1937. 导游

来源:互联网 发布:淘宝提升转化率 编辑:程序博客网 时间:2024/04/29 17:12

1937. 导游

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Mr. G. 在孟加拉国的一家旅游公司工作。他当前的任务是带一些游客去一些遥远的城市。和所有国家一样,一些城市之间有双向道路。每对相邻城市之间都有一条公交路线,每条路线都规定了自己的最大乘客数目。Mr. G. 有一份包含城市间道路状况和公交车最大载客量的地图。
往往无法一次性地将所有乘客带往目的地。例如,在下面7个城市的地图中,边代表道路,每条边上的数字代表这条道路上公交车的最大载客量。

如果Mr. G. 要将99位乘客从城市1带到城市7,则至少要往返5次(他必须陪同每一群乘客)。最佳路线是1-2-4-7。
 

Input

第一行为一个整数t,表示测试用例个数。 每组数据的第一行有两个整数N(N≤100)和R(R≤4950),分别表示城市的数量和道路的数量。接下来的R行每行有3个整数(C1,C2,P),其中C1和C2为城市编号,P(1<P<10000)是该道路上公交车的最大载客量。各城市编号为1~N的连续整数。第R+1行包含3个整数(S,D,T),分别表示出发城市,目的城市的编号和游客的数量(1<T<100000)。保证两个城市间最多只有一条道路。 

Output

对于每组输入数据,输出最少的往返次数。 

Sample Input

17 101 2 301 3 151 4 102 4 252 5 603 4 403 6 204 7 355 7 206 7 301 7 99

Sample Output

5

// Problem#: 1937// Submission#: 3369378// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <stdio.h>#include <iostream>#include <vector>#include <string>#include <stack>#include <iomanip>#include <algorithm>#include <queue>#include <functional>#include <map>#include <string.h>using namespace std;const int MAX_N = 105;const int INF = -1;int G[MAX_N][MAX_N];int N, R, S, E, P;void init() {    for (int i = 1; i <= N; i++) {        for (int j = 1; j <= N; j++) {            G[i][j] = INF;        }        G[i][i] = 0;    }}int main() {    std::ios::sync_with_stdio(false);    int caseNum;    cin >> caseNum;    while (caseNum--) {        cin >> N >> R;        init();        for (int i = 0; i < R; i++) {            int v1, v2, dis;            cin >> v1 >> v2 >> dis;            G[v1][v2] = G[v2][v1] = dis;        }        cin >> S >> E >> P;        for (int k = 1; k <= N; k++) {            for (int i = 1; i <= N; i++) {                for (int j = 1; j <= N; j++) {                    G[i][j] = max(G[i][j], min(G[i][k], G[k][j]));                }            }        }        cout << P / (G[S][E]- 1) + (P % G[S][E] ? 1 : 0) << endl;    }    //cin >> N;    return 0;}                                 


0 0
原创粉丝点击