이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const ll INF=1e18;
int n, m, k, b[100][1000], s[100][1000], profit[100][100];
ll d[100][100], dp[100][100];
bool ok(int x) {
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
dp[i][j]=i==j||d[i][j]>=INF?-INF:profit[i][j]-x*d[i][j];
for (int l=0; l<n; ++l)
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
dp[i][j]=max(dp[i][j], min(INF, dp[i][l]+dp[l][j]));
for (int i=0; i<n; ++i)
if (dp[i][i]>=0)
return 1;
return 0;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for (int i=0; i<n; ++i)
for (int j=0; j<k; ++j)
cin >> b[i][j] >> s[i][j];
memset(d, 0x3f, sizeof(d));
for (int i=0; i<n; ++i)
d[i][i]=0;
for (int i=0; i<m; ++i) {
int u, v, w;
cin >> u >> v >> w, --u, --v;
d[u][v]=w;
}
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
for (int l=0; l<k; ++l)
if (b[i][l]!=-1&&s[j][l]!=-1)
profit[i][j]=max(profit[i][j], s[j][l]-b[i][l]);
for (int l=0; l<n; ++l)
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
d[i][j]=min(d[i][j], d[i][l]+d[l][j]);
int lb=0, rb=1e9;
while(lb<rb) {
int mid=(lb+rb+1)/2;
if (ok(mid))
lb=mid;
else
rb=mid-1;
}
cout << lb;
return 0;
}
# | 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... |