이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Inf = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n, m, k;
cin >> n >> m >> k;
vector <vector <int>> s(n, vector <int> (k)), b(n, vector <int> (k));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) {
cin >> b[i][j] >> s[i][j];
}
}
vector <vector <int>> d(n, vector <int> (n, Inf));
for (int i = 0; i < m; ++i) {
int u, v, x;
cin >> u >> v >> x;
--u, --v;
d[u][v] = x;
}
for (int i = 0; i < n; ++i) d[i][i] = 0;
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]);
}
}
}
vector <vector <int>> best(n, vector <int> (n, 0));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int id = 0; id < k; ++id) {
if (s[j][id] != -1 && b[i][id] != -1) best[i][j] = max(best[i][j], s[j][id] - b[i][id]);
}
}
}
vector <vector <ll>> w(n, vector <ll> (n));
int l = 0, r = 1e9 + 7;
while (r - l > 1) {
int m = (l + r) >> 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (d[i][j] < Inf) w[i][j] = best[i][j] - (ll)m * d[i][j];
else w[i][j] = -1e18;
}
}
for (int i = 0; i < n; ++i) w[i][i] = 0;
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
w[i][j] = max(w[i][j], w[i][k] + w[k][j]);
}
}
}
bool fl = false;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != j && w[i][j] + w[j][i] >= 0) {
fl = true;
}
}
}
if (fl) l = m;
else r = m;
}
cout << l << '\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... |