이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <deque>
#include <queue>
#define ll long long
using namespace std;
ll dist[100][100], C[100][100], X[100][100], l, r, mid;
ll n, m, k, a, b, c, cur, A[100][1000], B[100][1000];
int main() {
cin >> n >> m >> k;
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j) {
dist[i][j] = 1e18;
}
}
for (int i=0; i<n; ++i) {
dist[i][i] = 0;
for (int j=0; j<k; ++j) {
cin >> A[i][j] >> B[i][j];
}
}
for (int i=0; i<m; ++i) {
cin >> a >> b >> c;
--a, --b;
dist[a][b] = min(dist[a][b], c);
}
for (int x=0; x<n; ++x) {
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j) {
dist[i][j] = min(dist[i][x] + dist[x][j], dist[i][j]);
}
}
}
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j) {
if (i != j) {
for (int x=0; x<k; ++x) {
if (min(A[i][x], B[j][x]) != -1) C[i][j] = max(C[i][j], B[j][x]-A[i][x]);
}
}
}
}
l = 0, r = 1e9;
while (l < r) {
mid = (l+r+1)/2;
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j) {
X[i][j] = C[i][j] - mid * dist[i][j];
}
}
for (int x=0; x<n; ++x) {
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j) {
X[i][j] = max(X[i][j], min((ll)1e18, X[i][x] + X[x][j]));
}
}
}
cur = -1e18;
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j) {
if (i != j) {
cur = max(cur, X[i][j]+X[j][i]);
}
}
}
if (cur >= 0) l = mid;
else r = mid-1;
}
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... |