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;
typedef long long ll;
const ll MXN = 120 , MXM = 10000 , MXK = 1020 , Inf = 1e10;
ll n,m,k;
ll profit[MXN][MXN] , dis[MXN][MXN];
ll buy[MXN][MXK] , sell[MXN][MXK];
ll gr[MXN][MXN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> m >> k;
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= k ; j++) {
cin >> buy[i][j] >> sell[i][j];
// if(buy[i][j] == -1) buy[i][j] = Inf;
// if(sell[i][j] == -1) sell[i][j] = -Inf;
}
}
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= n ; j++) {
dis[i][j] = Inf;
}
dis[i][i] = 0;
}
for(int i = 0 ; i < m ; i++) {
ll v,u,w; cin >> v >> u >> w;
dis[v][u] = w;
}
for(int k = 1 ; k <= n ; k++) {
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= n ; j++) {
dis[i][j] = min(dis[i][j] , dis[i][k] + dis[k][j]);
}
}
}
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= n ; j++) {
for(int x = 1 ; x <= k ; x++) {
if(sell[j][x] != -1 && buy[i][x] != -1) profit[i][j] = max(profit[i][j] , sell[j][x] - buy[i][x]);
}
}
}
ll l = 0 , r = 1000000000 + 200;
while(r-l > 1) {
ll m = (l+r)/2;
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= n ; j++) {
gr[i][j] = dis[i][j]*m - profit[i][j];
}
gr[i][i] = Inf;
}
for(int k = 1 ; k <= n ; k++) {
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= n ; j++) {
if(gr[i][k] < Inf) gr[i][j] = min(gr[i][j] , gr[i][k] + gr[k][j]);
// if(gr[i][k] + gr[k][j] < gr[i][j]-EPS) {
// gr[i][j] = gr[i][k] + gr[k][j];
// }
// if(gr[i][j] < -Inf) gr[i][j] = -Inf;
}
}
}
bool ok = 0;
for(int i = 1 ; i <= n ; i++) {
if(gr[i][i] <= 0) {
ok = 1; break;
}
}
if(ok) {
l = m;
} else {
r = m;
}
}
cout << l << "\n";
// printf("%.0lf\n" , l);
}
# | 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... |