이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
const int N = 105, C = 1000, INF = 2e9;
ll prof[N][N], dp[N][N],
b[N][N], s[N][N], w[N][N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
w[i][j] = INF;
}
}
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++) {
ll a, b, c;
cin >> a >> b >> c;
a--, b--;
w[a][b] = min(w[a][b], c);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
if (w[j][i] != INF && w[i][k] != INF) {
w[j][k] = min(w[j][k], w[j][i] + w[i][k]);
}
}
}
}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < n; j++) {
// cout << w[i][j] << " ";
// }
// cout << "\n";
// }
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
for (int z = 0; z < k; z++) {
if (b[x][z] != -1 && s[y][z] != -1) {
prof[x][y] = max(prof[x][y], s[y][z] - b[x][z]);
}
}
}
}
ll l = 0, r = 3e9;
while (r - l > 1) {
ll p = (l + r) >> 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (w[i][j] != INF) {
dp[i][j] = prof[i][j] - w[i][j] * p;
}
}
}
bool ok = false;
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
for (int z = 0; z < n; z++) {
if (w[y][x] != INF && w[x][z] != INF) {
dp[y][z] = max(dp[y][z], dp[y][x] + dp[x][z]);
if (y == z && dp[y][z] >= 0) {
ok = true;
}
}
}
}
}
if (ok) {
l = p;
}
else {
r = p;
}
}
cout << l;
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... |