이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1ll << 60;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int64_t N, M, K;
cin >> N >> M >> K;
vector<vector<int64_t>> B(N, vector<int64_t>(K)), S(N, vector<int64_t>(K));
for (int i = 0; i < N; i++) {
for (int j = 0; j < K; j++) {
cin >> B[i][j] >> S[i][j];
}
}
vector<vector<pair<int64_t, int64_t>>> G(N);
for (int i = 0; i < M; i++) {
int64_t u, v, t;
cin >> u >> v >> t;
u--, v--;
G[u].push_back({v, t});
}
vector dist(N, vector<long long>(N, INF));
for (int u = 0; u < N; u++) {
for (auto [v, t] : G[u]) {
dist[u][v] = t;
}
}
for (int i = 0; i < N; i++) {
dist[i][i] = 0;
}
for (int k = 0; k < N; k++)
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
vector profit(N, vector<int64_t>(N));
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
for (int k = 0; k < K; k++)
if (B[i][k] != -1 && S[j][k] != -1)
profit[i][j] = max(profit[i][j], (int64_t)S[j][k] - B[i][k]);
int64_t l = -1, r = 1 << 30;
while (r > l + 1) {
int64_t mid = (l + r) / 2;
vector dis(N, vector<__int128_t>(N, INF));
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (i != j)
dis[i][j] = min(INF, 1LL * min(2 * INF / mid, dist[i][j]) * mid - profit[i][j]);
for (int k = 0; k < N; k++)
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) {
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
if (dis[i][j] < -INF) {
dis[i][j] = -INF;
}
}
bool good = false;
for (int i = 0; i < N; i++) {
if (dis[i][i] <= 0) {
good = true;
}
}
if (good) {
l = mid;
} else {
r = mid;
}
}
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... |