#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define int ll
using ld = long double;
using pii = pair<int, int>;
#define F first
#define S second
#define sz(x) (int)x.size()
const ld PI = 3.1415926535;
const ld eps = 1e-9;
const int N = 1e3 + 5;
const int M = 7e6 + 1;
ll mod = 998244353;
const int infi = 1e9;
const ll infl = 1e16;
const int P = 31;
int mult(int a, int b) { return a * 1LL * b % mod; }
int sum(int a, int b) {
if(a + b >= mod)
return a + b - mod;
if(a + b < 0)
return a + b + mod;
return a + b;
}
ll binpow(ll a, ll n) {
if (n == 0) return 1;
if (n % 2 == 1) {
return binpow(a, n - 1) * a % (mod);
} else {
ll b = binpow(a, n / 2);
return b * b % (mod);
}
}
int n, m, k, b[101][1001], s[101][1001], d[101][101], fl[101][101];
void solve() {
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 = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
d[i][j] = infl;
for(int i = 1; i <= m; i++){
int u, v, w;
cin >> u >> v >> w;
d[u][v] = w;
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
if(d[i][k] != infl && d[k][j] != infl)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j++){
int mxbs = 0, mxsb = 0;
for(int c = 1; c <= k; c++){
if(b[i][c] != -1 && s[j][c] != -1)
mxbs = max(mxbs, s[j][c] - b[i][c]);
if(s[i][c] != -1 && b[j][c] != -1)
mxsb = max(mxsb, s[i][c] - b[j][c]);
}
fl[i][j] = mxbs;
fl[j][i] = mxsb;
if(d[i][j] != infl && d[j][i] != infl)
ans = max(ans, (mxbs + mxsb) / (d[i][j] + d[j][i]));
}
}
for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j++){
for(int c = j + 1; c <= n; c++){
if(d[i][j] != infl && d[j][c] != infl && d[c][i] != infl)
ans = max(ans, (fl[i][j] + fl[j][c] + fl[c][i]) / (d[i][j] + d[j][c] + d[c][i]));
if(d[j][i] != infl && d[c][j] != infl && d[i][c] != infl)
ans = max(ans, (fl[j][i] + fl[c][j] + fl[i][c]) / (d[j][i] + d[c][j] + d[i][c]));
}
}
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
for(int i = 1; i <= t; i ++){
solve();
}
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... |