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 j=1;j<=k;j++)
{
if(buy[K][j]!=-1&&sell[i][j]!=-1)
a[K][i]=max(a[K][i],sell[i][j]-buy[K][j]);
}
}
}
ll l=0,r=1e18,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)1e18/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]);
}
}
}
for(int i=1;i<=n;i++)
{
if(f[i][i]<=0)
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... |