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;
#define int long long
const int mxN = 105, mxK=1005;
const int INF = 1e18;
int n, m, K, u, v, w;
int b[mxN][mxK], s[mxN][mxK];
int p[mxN][mxN], dis[2][mxN][mxN];
void floydWarshall(int t){
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
dis[t][i][j] = min(dis[t][i][j],
dis[t][i][k]+dis[t][k][j]);
}
int32_t main(){
cin >> n >> m >> K;
memset(dis,63,sizeof(dis));
for(int i = 1; i <= n; i++)
for(int j = 1; j <= K; j++)
cin >> b[i][j] >> s[i][j];
for(int i = 0; i < m; i++)
cin>>u>>v>>w,dis[0][u][v]=w;
floydWarshall(0);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
for(int k = 1; k <= K; k++)
if(min(b[i][k],s[j][k])>=0)
p[i][j]=max(p[i][j],s[j][k]-b[i][k]);
int l = 0, r = 1e9;
while(l<r){
int mid = (l+r+1)/2, ok=0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
dis[1][i][j]=-p[i][j]+mid*
min(INF/mid,dis[0][i][j]);
floydWarshall(1);
for(int i = 1; i <= n;i++)
if(dis[1][i][i]<=0) ok=1;
if(ok) l=mid;
else r=mid-1;
}
cout << 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... |