-
Notifications
You must be signed in to change notification settings - Fork 0
/
10099.cpp
38 lines (34 loc) · 872 Bytes
/
10099.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <algorithm>
#include<cmath>
using namespace std;
int src, dest, weight, nodes, edges;
int dp[105][105];
int main(){
int t=1;
while(cin>>nodes >> edges){
if(nodes == 0 and edges == 0) return 0;
for(int i=1; i<=nodes; i++){
for(int j=1; j<=nodes; j++){
dp[i][j] = -1e6;
}
dp[i][i] = 0;
}
for(int i =0; i<edges; i++){
cin >>src >>dest >>weight;
dp[src][dest] = weight;
}
cin >> src >> dest >> weight;
for(int k=1; k<=nodes; k++){
for(int i=1; i<=nodes; i++){
for(int j=1; j<=nodes; j++){
dp[i][j] = dp[j][i] = max(dp[i][j], min(dp[i][k], dp[k][j]));
}
}
}
int result = ceil(((double)weight*1.0) / (dp[src][dest]-1));
printf("Scenario #%d\n", t++);
printf("Minimum Number of Trips = %d\n\n", result);
}
return 0;
}