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;
typedef long long ll;
const int Nmax = 105, Kmax = 1005;
const ll inf = 1e18;
int buy[Nmax][Kmax], sell[Nmax][Kmax];
int profit[Nmax][Nmax];
ll dist[Nmax][Nmax], dp[Nmax][Nmax];
int n, m, k;
void read()
{
int i, j, t, tmp;
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)
dist[i][j] = (i == j ? 0 : inf);
int x, y;
for(i=1; i<=m; ++i)
{
cin >> x >> y >> tmp;
dist[x][y] = tmp;
}
for(t=1; t<=n; ++t)
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
dist[i][j] = min(dist[i][t] + dist[t][j], dist[i][j]);
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
for(t=1; t<=k; ++t)
if(sell[j][t] != -1 && buy[i][t] != -1)
profit[i][j] = max(profit[i][j], sell[j][t] - buy[i][t]);
}
bool check(int E)
{
int i, j, t;
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
if(i == j) dp[i][j] = 0;
else if((long double) dist[i][j] * E <= inf)
dp[i][j] = profit[i][j] - (ll) dist[i][j] * E;
else dp[i][j] = -inf;
for(t=1; t<=n; ++t)
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
dp[i][j] = max(dp[i][j], dp[i][t] + dp[t][j]);
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
if(i != j && dp[i][j] + dp[j][i] >= 0) return 1;
return 0;
}
int main()
{
// freopen("input", "r", stdin);
cin.sync_with_stdio(false);
read();
int ans = 0, step;
for(step = (1<<29); step; step >>= 1)
if(check(ans + step)) ans += step;
cout << ans << '\n';
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... |