#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
signed main() {
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> status(n, vector<int>(2 * k));
for (auto &a : status) {
for (auto &b : a)
cin >> b;
}
const int bign = 1e18;
vector<vector<int>> adjmat(n, vector<int>(n, bign));
for (int i = 0; i < m; i++) {
int a, b, t;
cin >> a >> b >> t;
a--, b--;
adjmat[a][b] = t;
}
for (int i = 0; i < n; i++)
adjmat[i][i] = 0;
for (int rounds = 0; rounds < 6; rounds++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++)
adjmat[i][j] = min(adjmat[i][j], adjmat[i][k] + adjmat[k][j]);
struct frac {
ll a, b;
bool operator<(frac x) const { return a * x.b < b * x.a; }
frac operator+(frac x) { return {a + x.a, b + x.b}; }
};
vector<vector<int>> maxp(n, vector<int>(n, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int in = 0; in < k; in++) {
if (status[i][in * 2] != -1 && status[j][in * 2 + 1] != -1)
maxp[i][j] =
max(maxp[i][j], status[j][in * 2 + 1] - status[i][in * 2]);
}
}
}
for (auto a : adjmat) {
for (auto b : a)
cout << b << " ";
cout << "\n";
}
for (auto a : maxp) {
for (auto b : a)
cout << b << " ";
cout << "\n";
}
frac ans = {0, 1};
for (int i = 0; i < n; i++) {
vector<frac> vf(n, {0, bign});
for (int j = 0; j < n; j++)
vf[j] = {maxp[i][j], adjmat[i][j]};
for (int rounds = 0; rounds < n; rounds++) {
for (int st = 0; st < n; st++) {
for (int ed = 0; ed < n; ed++) {
vf[ed] = max(vf[ed], vf[st] + frac({maxp[st][ed], adjmat[st][ed]}));
}
}
cout << "ROUND: " << i << " " << rounds << "\n";
for (auto a : vf)
cout << a.a << "," << a.b << " ";
cout << "\n";
}
cout << "\n";
for (int j = 0; j < n; j++) {
auto tmp = vf[j] + frac({maxp[j][i], adjmat[j][i]});
cout << tmp.a << "," << tmp.b << " ";
ans = max(ans, tmp);
}
cout << "\n\n";
}
cout << ans.a / ans.b << "\n";
}
# | 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... |