이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e9;
int n, m, o;
vector<vector<ll>> b, s, d, p;
void precalc() {
for (int j = 0; j < n; j++) {
for (int i = 0; i < n; i++) {
for (int k = 0; k < n; k++) {
if (i == k) continue;
d[i][k] = min(d[i][k], d[i][j] + d[j][k]);
}
}
}
p.resize(n, vector<ll>(n, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (d[i][j] == INF) continue;
for (int k = 0; k < o; k++) {
if (s[j][k] == -1 or b[i][k] == -1) continue;
p[i][j] = max(p[i][j], s[j][k] - b[i][k]);
}
}
}
}
ll solve() {
ll lo = 0, hi = 1e9;
auto ok = [](ll x) {
vector<vector<ll>> dist(n, vector<ll>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
dist[i][j] = p[i][j] - d[i][j] * x;
}
}
for (int j = 0; j < n; j++) {
for (int i = 0; i < n; i++) {
for (int k = 0; k < n; k++) {
dist[i][k] = max(dist[i][k], dist[i][j] + dist[j][k]);
}
}
}
bool ret = 0;
for (int i = 0; i < n; i++) {
ret |= (dist[i][i] >= 0);
}
return ret;
};
while (hi - lo > 1) {
ll mid = (lo + hi) / 2;
if (ok(mid)) lo = mid;
else hi = mid - 1;
}
if (ok(hi)) return hi;
return lo;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> o;
b.resize(n, vector<ll>(o)), s.resize(n, vector<ll>(o));
for (int i = 0; i < n; i++) {
for (int j = 0; j < o; j++) {
cin >> b[i][j] >> s[i][j];
}
}
d.resize(n, vector<ll>(n, INF));
while (m--) {
int u, v;
ll w;
cin >> u >> v >> w;
d[u - 1][v - 1] = w;
}
precalc();
cout << solve() << '\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... |