#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int, int>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ld long double
int n,m,k, prof[105][105];
vector<vector<int>> dist(105, vector<int>(105, 1e15));
vector<vector<pll>> dp(105, vector<pll>(105));
vector<vector<pll>> v(105);
signed main(){
cin>>n>>m>>k;
for(int i=0;i<n;i++){
for(int j=0;j<k;j++){
int a,b;cin>>a>>b;
v[i].pb({a,b});
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int z=0;z<k;z++){
if(v[j][z].s==-1 or v[i][z].f == -1)continue;
prof[i][j]=max(prof[i][j],v[j][z].s-v[i][z].f);
}
//~ printf("from %lld to %lld, prof %lld\n", i, j, prof[i][j]);
}
}
//~ for(int i=0;i<n;i++)dist[i][i]=0;
for(int i=0;i<m;i++){
int a,b,c;cin>>a>>b>>c;
a--,b--;
dist[a][b]=c;
dist[b][a]=c;
}
for(int z=0;z<n;z++){
for(int j=0;j<n;j++){
for(int i=0;i<n;i++){
dist[i][j]=min(dist[i][z]+dist[z][j], dist[i][j]);
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
dp[i][j]={prof[i][j], dist[i][j]};
}
}
//~ for(int i=0;i<n;i++){
//~ for(int j=0;j<n;j++){
//~ cout<<prof[i][j]<<" ";
//~ }
//~ cout<<endl;
//~ }
//~ cout<<endl;
//~ for(int i=0;i<n;i++){
//~ for(int j=0;j<n;j++){
//~ cout<<dist[i][j]<<" ";
//~ }
//~ cout<<endl;
//~ }
//~ cout<<endl;
for(int z=0;z<n;z++){
for(int j=0;j<n;j++){
for(int i=0;i<n;i++){
if(z==i or z==j or i==j)continue;
if((ld)dp[i][j].f / (ld)(dp[i][j].s) <
(ld)(dp[i][z].f+dp[z][j].f)/(ld)(dp[i][z].s+dp[z][j].s)){
dp[i][j].f=dp[i][z].f+dp[z][j].f;
dp[i][j].s=dp[i][z].s+dp[z][j].s;
}
}
}
}
int ans=0;
for(int z=0;z<n;z++){
for(int j=0;j<n;j++){
for(int i=0;i<n;i++){
// i > j > z > i;
ans=max(ans, (dp[i][j].f+dp[j][z].f+dp[z][i].f)/(dp[i][j].s+dp[j][z].s+dp[z][i].s));
}
}
}
cout<<ans;
}
# | 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... |