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 pii pair<long long,long long>
#define f first
#define s second
#define ll long long
//vector<pii> g[111];
ll dis[111][111],a[111][111],f[111][111];
ll buy[111][1111],sell[111][1111];
int main()
{
int n,m,k;
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];
for(int j=1; j<=n; j++) dis[i][j]=1e18;
}
for(int i=1; i<=m; i++)
{
int u,v,w;
cin>>u>>v>>w;
dis[u][v]=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 K=1; K<=n; K++)
for(int j=1; j<=k; j++)
{
if(buy[i][j]!=-1&&sell[K][j]!=-1)
a[i][K]=max(a[i][K],sell[K][j]-buy[i][j]);
}
ll l=0,r=1e9,ans=0;
while(l<r)
{
ll mid=(l+r)/2;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
f[i][j]=mid*min((ll)1e15/mid,dis[i][j])-a[i][j];
}
for(int K=1; K<=n; K++)
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
f[i][j]=min(f[i][j],f[i][K]+f[K][j]);
}
}
}
bool ch=0;
for(int i=1; i<=n; i++)
{
if(f[i][i]<=0)
{
ch=1;
}
}
if(ch)
ans=mid,l=mid+1;
else
r=mid-1;
}
cout<<ans;
}
# | 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... |