-
Notifications
You must be signed in to change notification settings - Fork 0
/
10217.cpp
48 lines (45 loc) · 1004 Bytes
/
10217.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
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<cstring>
using namespace std;
int n,m,k;
int cost[101][101];
int tim[101][101];
const int INF = 50000;
int main(){
int t; scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&k);
for( int i = 1 ; i <= n ; ++i ){
for( int j = 1 ; j <= n ; ++j ){
cost[i][j] = tim[i][j] = INF;
}
}
for( int i = 0 ; i < k ; ++i ){
int u,v,x,d; scanf("%d%d%d%d",&u,&v,&x,&d);
cost[u][v] = x;
tim[u][v] = d;
}
//floyd-warshall
for( int i = 1 ; i <= n ; ++i ){
for( int j = 1 ; j <= n ; ++j ){
if( i == j ) continue;
for( int k = 1; k <= n ; ++k ){
if( cost[i][k] == INF || cost[k][j] == INF ) continue;
cost[i][j] = min(cost[i][k]+cost[k][j], cost[i][j]);
tim[i][j] = min(tim[i][k]+tim[k][j], tim[i][j]);
}
}
}
for( int i = 1 ; i <= n ; ++i ){
printf("%d(%d,%d) ", i, cost[1][i], tim[1][i]);
}
if( cost[1][n] > m ){
printf("Poor KCM\n");
continue;
}
else{
printf("%d\n",tim[1][n]);
}
}
return 0;
}