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;
const long long N = 105;
long long mind[N][N];
long long maxp[N][N];
long double newc[N][N];
long long b[N][1005];
long long s[N][1005];
long double dst[N];
long long n;
bool check(long double R){
// if(R == 0.5)
// cerr<<"-1\n";;
for(long long i =1 ; i<=n;i++)
for(long long j =1 ; j<=n;j++){
if(mind[i][j] == LLONG_MAX)
newc[i][j] = LDBL_MAX;
else
newc[i][j] = 1.0 * R * mind[i][j] - maxp[i][j];
}
for(long long i=1;i<=n;i++)
dst[i] = LDBL_MAX;
dst[1] = 0;
for(long long nr = 1; nr <n;nr++){
for(long long i = 1; i<=n;i++)
for(long long j =1 ; j<=n;j++){
if(newc[i][j] != LDBL_MAX && dst[i] != LDBL_MAX && dst[i] + newc[i][j] < dst[j])
dst[j] = dst[i] + newc[i][j];
}
}
for(long long i =1 ; i<=n;i++){
for(long long j =1 ; j<=n;j++)
if(newc[i][j] != LDBL_MAX && dst[i] != LDBL_MAX && dst[i] + newc[i][j] < dst[j])
return true;
}
return false;
}
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
long long m, k;
cin>>n>>m>>k;
for(long long i=1;i<=n;i++){
for(long long j = 1; j<=k;j++)
cin>>b[i][j]>>s[i][j];
}
for(long long i = 1; i<=n;i++)
for(long long j = 1; j<=n;j++)
mind[i][j] = LLONG_MAX;
for(long long i = 1; i<=n;i++)
mind[i][i] = 0;
for(long long i = 1; i<=m;i++){
long long x, y, d;
cin>>x>>y>>d;
mind[x][y] = d;
}
for(long long k = 1 ; k<=n;k++){
for(long long i =1 ; i<=n;i++)
for(long long j =1 ; j<=n;j++){
if(mind[i][k] != LLONG_MAX && mind[k][j] != LLONG_MAX && mind[i][j] > mind[i][k] + mind[k][j])
mind[i][j] = mind[i][k] + mind[k][j];
}
}
for(long long i = 1; i<=n;i++){
for(long long j = 1; j<=n;j++){
maxp[i][j] = 0;
for(long long l = 1; l<=k;l++){
if(b[i][l] == -1 || s[j][l] == -1)
continue;
maxp[i][j] = max(maxp[i][j], s[j][l] - b[i][l]);
}
}
}
long double pas = -1LL<<60;
for(long double p2 = 1LL<<61; p2 > 0; p2/=2){
if(check(pas + p2))
pas +=p2;
}
if(check(pas + 0.999999999999) == true)
pas++;
cout<<pas;
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... |