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 int long long
const int N = 105;
const int K = 1010;
const int M = 9999;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int n, m, k;
int b[N][K];
int s[N][K];
int v[M], w[M], t[M];
int mx[N][N];
long long d[N][N];
long long dd[N][N];
signed main() {
ios::sync_with_stdio(false);
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];
}
}
for (int i = 0; i < m; ++i) {
cin >> v[i] >> w[i] >> t[i];
--v[i];
--w[i];
}
memset(d, 0x3f, sizeof(d));
for (int i = 0; i < n; ++i) {
d[i][i] = 0;
}
for (int i = 0; i < m; ++i) {
d[v[i]][w[i]] = min<long long>(d[v[i]][w[i]], t[i]);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int f = 0; f < n; ++f) {
if (d[j][i] < INF && d[i][f] < INF) {
d[j][f] = min(d[j][f], d[j][i] + d[i][f]);
}
}
}
}
memcpy(dd, d, sizeof(dd));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
mx[i][j] = 0;
for (int f = 0; f < k; ++f) {
if (b[i][f] != -1 && s[j][f] != -1) {
mx[i][j] = max(mx[i][j], s[j][f] - b[i][f]);
}
}
}
}
int l = 0, r = 1e9;
while (r - l > 1) {
int mid = (l + r) / 2;
memcpy(d, dd, sizeof(d));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != j && d[i][j] < INF) {
d[i][j] = d[i][j] * mid - mx[i][j];
assert(d[i][j] < INF);
}
}
}
for (int i = 0; i < n; ++i) {
d[i][i] = INF;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int f = 0; f < n; ++f) {
if (d[j][i] < INF && d[i][f] < INF) {
d[j][f] = min(d[j][f], d[j][i] + d[i][f]);
}
}
}
}
bool ok = false;
for (int i = 0; i < n; ++i) {
ok |= d[i][i] <= 0;
}
if (ok) {
l = mid;
} else {
r = mid;
}
}
cout << l << endl;
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... |