This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
long long n,m,kk,buy[101][1001],sell[101][1001],graph[101][101],graph2[101][101],profit[101][101];
void floyd(long long adj[101][101]){
for(int k = 1 ; k <= n ; k += 1){
for(int i = 1 ; i <= n ; i += 1){
for(int j = 1 ; j <= n ; j += 1){
adj[i][j] = min(adj[i][j],adj[i][k]+adj[k][j]);
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
cin >> n >> m >> kk;
for(int i = 1 ; i <= n ; i += 1){
for(int j = 1 ; j <= n ; j += 1){
graph[i][j] = INF;
}
for(int j = 1 ; j <= kk ; j += 1){
cin >> buy[i][j] >> sell[i][j];
}
}
for(int i = 0 ; i < m ; i += 1){
int a,b,c;
cin >> a >> b >> c;
graph[a][b] = c;
}
floyd(graph);
for(int i = 1 ; i <= n ; i += 1){
for(int j = 1 ; j <= n ; j += 1){
for(int k = 1 ; k <= kk ; k += 1){
if(sell[j][k] != -1 && buy[i][k] != -1){
profit[i][j] = max(profit[i][j],sell[j][k]-buy[i][k]);
}
}
}
}
long long first = 0 , last = INF;
while(last-first > 1){
long long mid = (first+last)/2;
for(int i = 1 ; i <= n ; i += 1){
for(int j = 1 ; j <= n ; j += 1){
graph2[i][j] = mid*graph[i][j] - profit[i][j];
}
}
floyd(graph2);
bool good = false;
for(int i = 1 ; i <= n ; i += 1){
if(graph2[i][i] <= 0){
good = true;
break;
}
}
if(good){
first = mid;
}else{
last = mid;
}
}
cout << first << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |