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 ar array
const ll INF=1e18;
int n, m, k, b[100][1000], s[100][1000], profit[100][100];
ll d[100][100], dp[100][100];
bool ok(int x) {
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
dp[i][j]=i==j||d[i][j]>=INF?-INF:profit[i][j]-x*d[i][j];
for (int l=0; l<n; ++l)
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
dp[i][j]=max(dp[i][j], min(INF, dp[i][l]+dp[l][j]));
for (int i=0; i<n; ++i)
if (dp[i][i]>=0)
return 1;
return 0;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for (int i=0; i<n; ++i)
for (int j=0; j<k; ++j)
cin >> b[i][j] >> s[i][j];
memset(d, 0x3f, sizeof(d));
for (int i=0; i<n; ++i)
d[i][i]=0;
for (int i=0; i<m; ++i) {
int u, v, w;
cin >> u >> v >> w, --u, --v;
d[u][v]=w;
}
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
for (int l=0; l<k; ++l)
if (b[i][l]!=-1&&s[j][l]!=-1)
profit[i][j]=max(profit[i][j], s[j][l]-b[i][l]);
for (int l=0; l<n; ++l)
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
d[i][j]=min(d[i][j], d[i][l]+d[l][j]);
int lb=0, rb=1e9;
while(lb<rb) {
int mid=(lb+rb+1)/2;
if (ok(mid))
lb=mid;
else
rb=mid-1;
}
cout << lb;
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... |