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