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>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e9;
const ll mod = 1e9+7;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t z;
const int mxn = 2e2;
int n, m, K;
ll c1[mxn][1000];
ll c2[mxn][1000];
ll w[mxn][mxn];
ll d[mxn][mxn];
void FloydWarshall(){
fr(i, 0, n) fr(j, 0, n) d[i][j] = w[i][j];
fr(k, 0, n){
fr(i, 0, n){
fr(j, 0, n){
d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
}
}
}
}
pair<ll,ll> best[mxn][mxn];
void FloydWarshall2(){
fr(k, 0, n){
fr(i, 0, n){
fr(j, 0, n){
ll sum = best[i][k].st + best[k][j].st;
ll tim = best[i][k].nd + best[k][j].nd;
if(sum * best[i][j].nd > tim * best[i][j].st){
best[i][j] = {sum, tim};
}
}
}
}
}
void solve(){
cin >> n >> m >> K;
fr(i, 0, n){
fr(j, 0, K){
cin >> c1[i][j];
}
fr(j, 0, K){
cin >> c2[i][j];
}
}
fr(i, 0, n){
fr(j, 0, n){
if(i == j) w[i][j] = 0;
else w[i][j] = inf;
}
}
fr(i, 0, m){
int u, v;
cin >> u >> v;
--u, --v;
cin >> w[u][v];
}
FloydWarshall();
fr(i, 0, n){
best[i][i] = {0, inf};
}
fr(i, 0, n){
fr(j, 0, n){
if(i==j) continue;
ll mx = 0;
fr(k, 0, K){
if(c1[i][k] == -1 || c2[j][k] == -1) continue;
mx = max(mx, c2[j][k] - c1[i][k]);
}
best[i][j] = {mx, d[i][j]};
}
}
FloydWarshall2();
/*fr(i, 0, n){
fr(j, 0, n){
if(i == j) cout<<"(0, 0) ";
else cout<<'('<<best[i][j].st<<", "<<best[i][j].nd<<") ";
}
cout<<endl;
}
*/
ll a = 0;
ll b = inf;
fr(i, 0, n){
fr(j, 0, n){
if(i == j) continue;
ll ap = best[i][j].st + best[j][i].st;
ll bp = best[i][j].nd + best[j][i].nd;
if(a*bp < b*ap){
a = ap;
b = bp;
}
}
}
cout<<a/b<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | 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... |