이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
const long long inf = 1e18;
const int N = 105;
int d[N][N], s[N][N];
int tr[N][1005][2];
int t[N][N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, m, k; cin>>n>>m>>k;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) d[i][j] = inf;
for(int i=1;i<=n;i++){
for(int j=0;j<k;j++){
cin>>tr[i][j][0]>>tr[i][j][1];
}
}
for(int i=0;i<m;i++){
int a, b, c; cin>>a>>b>>c;
d[a][b] = min(d[a][b], c);
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int l=0;l<k;l++){
if(~tr[i][l][0] && ~tr[j][l][1]){
s[i][j] = max(s[i][j], tr[j][l][1] - tr[i][l][0]);
}
}
}
}
auto check = [&](int f){
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) t[i][j] = -inf;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i == j || d[i][j] == inf) continue;
t[i][j] = max(t[i][j], s[i][j] - d[i][j] * f);
}
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
t[i][j] = max(t[i][j], t[i][k] + t[k][j]);
}
}
}
//~ for(int i=1;i<=n;i++){
//~ for(int j=1;j<=n;j++){
//~ cout<<t[i][j]<<" ";
//~ } cout<<"\n";
//~ } cout<<"\n";
for(int i=1;i<=n;i++){
if(t[i][i] >= 0) return true;
} return false;
};
int l = 0, r = 1e9;
while(l < r){
int m = (l + r + 1) >> 1;
if(check(m)) l = m;
else r = m - 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... |