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>
#define int long long
using namespace std;
const int MAXN = 50 + 2, INF = 1000 * 1000 * 1000 + 123, MAXK = 50 + 2;
/*
4 5 2
10 9 5 2
6 4 20 15
9 7 10 9
-1 -1 16 11
1 2 1
2 3 1
1 4 1
4 3 1
3 1 1
*/
int n, m, kk, d[MAXN][MAXN], b[MAXN][MAXK], s[MAXN][MAXK], dp[MAXN][MAXN][MAXN];
long double ans;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m >> kk;
if (n >= MAXN || kk >= MAXK) return 0;
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j) d[i][j] = INF;
for (int i = 0; i < n; i++) for (int j = 0; j < kk; j++) cin >> b[i][j] >> s[i][j];
{
int v, w, t;
for (int i = 0; i < m; i++) {
cin >> v >> w >> t;
d[--v][--w] = t;
if (t != 1) return 0;
}
}
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) dp[i][j][k] = -INF * 100ll;
for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dp[d[i][j]][i][j] = 0;
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < kk; k++) if (s[j][k] > b[i][k] && d[i][j] < n && ~b[i][k])
dp[d[i][j]][i][j] = max(dp[d[i][j]][i][j], s[j][k] - b[i][k]);
for (int k = 1; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int o = 0; o < n; o++)
if (d[i][o] + d[o][j] <= k && dp[d[i][o]][i][o] >= 0 && dp[k - d[i][o]][o][j] >= 0) dp[k][i][j] = max(dp[k][i][j], dp[d[i][o]][i][o] + dp[k - d[i][o]][o][j]);
for (int i = 2; i <= n; i++) for (int j = 0; j < n; j++) {
if (dp[i][j][j] < 0) continue;
ans = max(ans, (long double) dp[i][j][j] / i);
// cout << i << ' ' << a << ' ' << b << ' ' << dp[j][a][b] << ' ' << dp[i - j][b][a] << ' ' << i << endl;
}
cout << (int)ans;
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... |