이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
const int N = 101;
const int K = 1001;
const ll INF = (ll)1e18;
int n, m, k;
ll B[N][K], S[N][K], mx[N][N], dist[N][N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
for(int i = 1 ; i < N ; i++){
for(int j = 1 ; j < N ; j++){
dist[i][j] = INF;
}
}
cin >> n >> m >> k;
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= k ; j++){
cin >> B[i][j] >> S[i][j];
}
}
for(int i = 0 ; i < m ; i++){
int x, y, z;
cin >> x >> y >> z;
dist[x][y] = z;
}
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= n ; j++){
for(int p = 1 ; p <= k ; p++){
if(B[i][p] != -1 && S[j][p] != -1){
mx[i][j] = max(mx[i][j], S[j][p] - B[i][p]);
}
}
}
}
int l = 0, r = (int)1e9;
while(l <= r){
int mid = (l + r) / 2;
vector <vector <ll> > c(n + 1, vector <ll>(n + 1));
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= n ; j++){
c[i][j] = mx[i][j] - (dist[i][j] == INF ? INF : dist[i][j] * mid);
}
}
for(int k = 1 ; k <= n ; k++){
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= n ; j++){
c[i][j] = max(c[i][j], c[i][k] + c[k][j]);
}
}
}
bool ok = 0;
for(int i = 1 ; i <= n ; i++){
if(c[i][i] >= 0) ok = 1;
}
if(ok) l = mid + 1;
else r = mid - 1;
}
cout << r << endl;
}
# | 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... |