이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 101;
const int mxK = 1001;
const long long INF = 1e18;
int s[mxN][mxK], b[mxN][mxK];
long long dist[mxN][mxN];
long long profit[mxN][mxN];
int n, m, k;
void pre_calc() {
for (int x = 1; x <= n; x++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dist[i][j] = min(dist[i][j], dist[i][x] + dist[x][j]);
}
}
}
for (int item = 1; item <= k; item++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) {
profit[i][j] = 0;
continue;
}
if (b[i][item] != -1 && s[j][item] != -1) {
profit[i][j] = max(profit[i][j], (long long) s[j][item] - b[i][item]);
}
}
}
}
}
bool f(int x) {
__int128 d[mxN];
__int128 edge[mxN][mxN];
for (int i = 1; i <= n; i++) {
d[i] = INF;
for (int j = 1; j <= n; j++) {
edge[i][j] = (__int128) x * dist[i][j] - profit[i][j];
}
}
for (int l = 1; l <= n; l++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
edge[i][j] = min(edge[i][j], edge[i][l] + edge[l][j]);
}
}
}
for (int i = 1; i <= n; i++) {
if (edge[i][i] <= 0) return true;
}
return false;
}
void testCase() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dist[i][j] = INF;
profit[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
cin >> b[i][j] >> s[i][j];
}
}
while (m--) {
int u, v, w;
cin >> u >> v >> w;
dist[u][v] = min(dist[u][v], 1LL * w);
}
pre_calc();
int lo = 0, hi = 1e9 + 5;
while (lo < hi) {
int mid = (lo + hi + 1) >> 1;
if (f(mid)) lo = mid;
else hi = mid - 1;
}
cout << lo << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'bool f(int)':
merchant.cpp:36:12: warning: variable 'd' set but not used [-Wunused-but-set-variable]
36 | __int128 d[mxN];
| ^
# | 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... |