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 ll long long
#define ss second
#define ff first
#define INF 4000000000000000000
#define pb push_back
ll n,m,l,r,i,j,ii,jj,k,x,y,T,s,e,adj[101][101],ashig[101][101],adj1[101][101],buy[101][1001],sell[101][1001];
bool floyd_warshall(ll graph[101][101]){
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k]);
for(int i=1;i<=n;i++) if(graph[i][i]<=0) return true;
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>m>>k;
for(i=1;i<=n;i++)
for(j=1;j<=k;j++)
cin>>buy[i][j]>>sell[i][j];
for(i=1;i<=n;i++) for(j=1;j<=n;j++) adj[i][j]=INF;
for(i=1;i<=m;i++){
cin>>l>>r>>e;
adj[l][r]=e;
}
floyd_warshall(adj);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
for(ii=1;ii<=k;ii++)
if(buy[i][ii]!=-1 && sell[j][ii]!=-1) ashig[i][j]=max(ashig[i][j],sell[j][ii]-buy[i][ii]);
l=0;
r=2e9;
while(r-l>1){
m=(r+l)/2;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
adj1[i][j]=min(adj[i][j],(INF)/m)*m-ashig[i][j];
if(floyd_warshall(adj1)) l=m;
else r=m-1;
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++) adj1[i][j]=adj[i][j]*r-ashig[i][j];
if(floyd_warshall(adj1)) cout<<r;
else 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... |