이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// editorial exists
// also i like 42
// so im adding comments to make it 42 lines
// yay 42 lines :)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stMx(a,b) a = max(a,b)
#define stMn(a,b) a = min(a,b)
#define BIGNO (int)1210201069
#define REP(i, a, b) for(int i = a; i < b; i++)
int32_t main() {
int n, m, K, v, w, t; cin >> n >> m >> K;
int B[n][K], S[n][K], time[n][n], profit[n][n], relprofit[n][n];
REP(i, 0, n) REP(j, 0, n) {
time[i][j] = BIGNO; profit[i][j] = 0;
}
REP(i, 0, n) REP(j, 0, K) {
cin >> B[i][j] >> S[i][j];
if(B[i][j] == -1) B[i][j] = BIGNO;
}
REP(i, 0, m) {
cin >> v >> w >> t; v--; w--;
time[v][w] = t;
}
REP(i, 0, n) time[i][i] = 0;
REP(k, 0, n) REP(i, 0, n) REP(j, 0, n) stMn(time[i][j], time[i][k] + time[k][j]);
REP(i, 0, n) REP(j, 0, n) REP(k, 0, K) stMx(profit[i][j], S[j][k] - B[i][k]);
int l = 0, h = 1000000001;
while(h - l > 1) {
int mid = (l + h) / 2;
REP(i, 0, n) REP(j, 0, n) {
relprofit[i][j] = profit[i][j] - time[i][j] * mid;
if(i == j && profit[i][i] == 0 && relprofit[i][i] == 0) relprofit[i][i] = -1;
}
REP(k, 0, n) REP(i, 0, n) REP(j, 0, n) stMx(relprofit[i][j], relprofit[i][k] + relprofit[k][j]);
bool nonnegcycle = false; REP(i, 0, n) if(relprofit[i][i] >= 0) nonnegcycle = true;
if(nonnegcycle) l = mid;
else h = mid;
}
cout << l;
}
# | 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... |