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;
long long buy[105][1005], sell[105][1005], dist[105][105], dist2[105][105], profit[105][105];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, o, l=0, r=1e9;
cin >> n >> m >> o;
for (long long i=1; i<=n; i++)
for (long long j=1; j<=o; j++)
cin >> buy[i][j] >> sell[i][j];
for (long long i=1; i<=n; i++)
for (long long j=1; j<=n; j++)
dist[i][j]=2e9;
for (long long i=1; i<=m; i++)
{
long long u, v, w;
cin >> u >> v >> w;
dist[u][v]=w;
}
for (long long i=1; i<=n; i++)
for (long long j=1; j<=n; j++)
for (long long k=1; k<=n; k++)
dist[j][k]=min(dist[j][k], dist[j][i]+dist[i][k]);
for (long long i=1; i<=n; i++)
for (long long j=1; j<=n; j++)
for (long long k=1; k<=o; k++)
if (buy[i][k]!=-1 && sell[j][k]!=-1)
profit[i][j]=max(profit[i][j], sell[j][k]-buy[i][k]);
while (l<r)
{
long long mid=(l+r+1)/2;
for (long long i=1; i<=n; i++)
for (long long j=1; j<=n; j++)
dist2[i][j]=dist[i][j]*mid-profit[i][j];
for (long long i=1; i<=n; i++)
for (long long j=1; j<=n; j++)
for (long long k=1; k<=n; k++)
dist2[j][k]=min(dist2[j][k], dist2[j][i]+dist2[i][k]);
bool ok=0;
for (long long i=1; i<=n; i++)
{
if (dist2[i][i]<=0)
{
ok=1;
break;
}
}
if (ok)
l=mid;
else
r=mid-1;
}
cout << l;
return 0;
}
# | 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... |