이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<stdint.h>
using namespace std;
#define IOS {cin.tie(0);ios_base::sync_with_stdio(false);}
#define int int64_t
#define N 105
#define K 1005
const int INF = 1e14;
const double eps = 1e-6;
int n;
int bb[N][K],ss[N][K];
int w[N][N],dis[N][N];
double dp[N][N];
bool chk(double mm){
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) {
if(dis[i][j] == INF) dp[i][j] = INF;
else dp[i][j] = mm*dis[i][j] - w[i][j];
}
for(int x=1;x<=n;x++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) {
dp[i][j] = min(dp[i][j],dp[i][x] + dp[x][j]);
}
for(int i=1;i<=n;i++) if(dp[i][i] < 0) return true;
return false;
}
int32_t main()
{
IOS;
int m,k,a,b,t;
cin >> n >> m >> k;
for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) cin >> bb[i][j] >> ss[i][j];
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dis[i][j] = INF;
for(int i=1;i<=n;i++) dis[i][i] = 0;
for(int i=0;i<m;i++){
cin >> a >> b >> t;
dis[a][b] = t;
}
for(int x=1;x<=n;x++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++)
dis[i][j] = min(dis[i][j],dis[i][x] + dis[x][j]);
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){
if(j != i && dis[i][j] != INF) {
for(int x=1;x<=k;x++) if(ss[j][x] >= 0 && bb[i][x] >= 0) w[i][j] = max(w[i][j],ss[j][x] - bb[i][x]);
}
else w[i][j] = 0;
}
double l=eps,r = INF;
for(int cnt=0;cnt<120;cnt++){
double mm = (l+r)*0.5;
if(chk(mm)) l = mm;
else r = mm;
}
int ll = (floor(l));
while(chk(ll+1-eps)) ll++;
cout << ll << '\n';
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... |