This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
long long n,m,k;
long long b[105][1005],s[105][1005],d[105][105];
long long adj[105][105],aral[105][105];
long long setup[105][105];
const long long inf=10e9;
long double ans;
int main(){
long long an = 0;
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];
if(b[i][j] == -1) an++;
}
}
if(an == (n - 1) * k){
for (int i = 1; i < n; i++) for (int j = 0; j < k; j++) if (b[i][j] != -1) return 0;
{
int v, w, t;
for (int i = 0; i < m; i++) {
cin >> v >> w >> t;
d[--v][--w] = t;
}
}
for (int p = 0; p < n; p++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d[i][j] = min(d[i][j], d[i][p] + d[p][j]);
for (int i = 1; i < n; i++) for (int j = 0; j < k; j++) if (~b[0][j] && ~s[i][j]) ans = max(ans, (long double)(s[i][j] - b[0][j]) / (d[0][i] + d[i][0]));
cout << (int)ans;
return 0;
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++) adj[i][j] = inf;
}
for(int i = 1;i <= m;i++){
long long u,v,w;
cin >> u >> v >> w;
adj[u][v] = w;
}
for(int l = 1;l <= n;l++){
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
adj[i][j] = min(adj[i][j] , adj[i][l] + adj[l][j]);
}
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
if(adj[i][j] >= inf){
setup[i][j] =- inf;
continue;
}
for(int cnt = 1;cnt <= k;cnt++){
if(s[j][cnt] == -1 || b[i][cnt] == -1) continue;
setup[i][j] = max(setup[i][j] , s[j][cnt] - b[i][cnt]);
}
}
}
long long lower=0,higher=inf;
while(lower<higher){
long long mid = (lower + higher + 1) / 2;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
if(adj[i][j] >= inf) aral[i][j] = -inf;
else aral[i][j] = setup[i][j] - mid * adj[i][j];
}
}
for(int l=1;l<=n;l++){
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
if(adj[i][l] >= inf || adj[j][l] >= inf) continue;
aral[i][j] = max(aral[i][j] , aral[i][l] + aral[l][j]);
}
}
}
bool check = false;
for(int i = 1;i <= n;i++){
if(aral[i][i] >= 0){
check = true;
break;
}
}
if(check) lower=mid;
else higher=mid-1;
}
cout<<lower<<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... |