#include <iostream>
#include <cstring>
#define MAXN 103
#define MAXK 1003
const long long INF = 1e10;
using namespace std;
typedef long long ll;
int N , M , K , T[MAXN][MAXN] ;
long long profit[MAXN][MAXN] , adj[MAXN][MAXN] , adj2[MAXN][MAXN] , B[MAXN][MAXN] , S[MAXN][MAXN] , dist[MAXN][MAXN];
bool check(int x){
for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++){
if(i == j || dist[i][j] == INF){adj[i][j] = -INF; continue;}
adj[i][j] = (ll)profit[i][j] - (ll)dist[i][j]*x;
adj[i][j] = max(-INF, adj[i][j]);
}
}
for(int k=1; k<=N; k++)
for(int i=1; i<=N; i++)
for(int j=1; j<=N; j++){
adj[i][j] = max(adj[i][j] , adj[i][k] + adj[k][j]);
if(adj[i][i] >= 0) return true;
adj[i][j] = min(INF , adj[i][j]);
adj2[i][j] = adj[i][j];
}
/*cout << endl;
for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++)
cout << adj[i][j] << " " ;
cout << endl;
}
cout << endl;*/
for(int k=1; k<=N; k++)
for(int i=1; i<=N; i++)
for(int j=1; j<=N; j++){
adj2[i][j] = max(adj2[i][j] , adj2[i][k] + adj2[k][j]);
if(adj2[i][j] > adj[i][j]) return true;
}
return false;
}
int main(){
cin >> N >> M >> K;
for(int i=1; i<=N; i++)
for(int k=0; k<K; k++) cin >> B[i][k] >> S[i][k];
for(int i=0; i<=N; i++)
for(int j=0; j<=N; j++) dist[i][j] = INF;
for(int i=1; i<=N; i++) dist[i][i] = 0;
for(int i=0; i<M; i++){
int u,v; cin >> u >> v;
cin >> dist[u][v];
}
for(int k=1; k<=N; k++)
for(int i=1; i<=N; i++)
for(int j=1; j<=N; j++)
dist[i][j] = min(dist[i][j] , dist[i][k] + dist[k][j]);
for(int i=1; i<=N; i++)
for(int j=1; j<=N; j++){
profit[i][j] = 0;
for(int k=0; k<K; k++){
if(B[i][k] == -1 || S[j][k] == -1) continue;
profit[i][j] = max(profit[i][j] , S[j][k] - B[i][k]);
}
}
/*for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++)
cout << dist[i][j] << " " ;
cout << endl;
}*/
long long low = 0 , high = 1e9 + 1 , ANS = 0;
while(low <= high){
ll mid = (low + high)/2;
//cout << low << " " << mid << " " << high << endl;
if(check(mid)) {ANS = max(ANS , mid); low = mid + 1;}
else high = mid - 1;
}
cout << ANS << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
213 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
852 KB |
Output is correct |
2 |
Correct |
20 ms |
852 KB |
Output is correct |
3 |
Correct |
18 ms |
852 KB |
Output is correct |
4 |
Correct |
18 ms |
852 KB |
Output is correct |
5 |
Correct |
19 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
7 |
Correct |
23 ms |
852 KB |
Output is correct |
8 |
Correct |
17 ms |
852 KB |
Output is correct |
9 |
Correct |
12 ms |
852 KB |
Output is correct |
10 |
Correct |
14 ms |
852 KB |
Output is correct |
11 |
Correct |
16 ms |
852 KB |
Output is correct |
12 |
Correct |
16 ms |
852 KB |
Output is correct |
13 |
Correct |
14 ms |
892 KB |
Output is correct |
14 |
Correct |
15 ms |
892 KB |
Output is correct |
15 |
Correct |
16 ms |
892 KB |
Output is correct |
16 |
Correct |
15 ms |
892 KB |
Output is correct |
17 |
Correct |
19 ms |
892 KB |
Output is correct |
18 |
Correct |
2 ms |
892 KB |
Output is correct |
19 |
Correct |
15 ms |
892 KB |
Output is correct |
20 |
Correct |
16 ms |
892 KB |
Output is correct |
21 |
Correct |
22 ms |
892 KB |
Output is correct |
22 |
Correct |
14 ms |
892 KB |
Output is correct |
23 |
Correct |
13 ms |
892 KB |
Output is correct |
24 |
Correct |
18 ms |
892 KB |
Output is correct |
25 |
Correct |
15 ms |
892 KB |
Output is correct |
26 |
Correct |
2 ms |
892 KB |
Output is correct |
27 |
Correct |
12 ms |
892 KB |
Output is correct |
28 |
Correct |
14 ms |
892 KB |
Output is correct |
29 |
Correct |
12 ms |
892 KB |
Output is correct |
30 |
Correct |
2 ms |
892 KB |
Output is correct |
31 |
Correct |
20 ms |
892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
1124 KB |
Output is correct |
2 |
Incorrect |
237 ms |
1124 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
852 KB |
Output is correct |
2 |
Correct |
20 ms |
852 KB |
Output is correct |
3 |
Correct |
18 ms |
852 KB |
Output is correct |
4 |
Correct |
18 ms |
852 KB |
Output is correct |
5 |
Correct |
19 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
7 |
Correct |
23 ms |
852 KB |
Output is correct |
8 |
Correct |
17 ms |
852 KB |
Output is correct |
9 |
Correct |
12 ms |
852 KB |
Output is correct |
10 |
Correct |
14 ms |
852 KB |
Output is correct |
11 |
Correct |
16 ms |
852 KB |
Output is correct |
12 |
Correct |
16 ms |
852 KB |
Output is correct |
13 |
Correct |
14 ms |
892 KB |
Output is correct |
14 |
Correct |
15 ms |
892 KB |
Output is correct |
15 |
Correct |
16 ms |
892 KB |
Output is correct |
16 |
Correct |
15 ms |
892 KB |
Output is correct |
17 |
Correct |
113 ms |
1124 KB |
Output is correct |
18 |
Incorrect |
237 ms |
1124 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |