#include<bits/stdc++.h>
using namespace std;
// #define ll long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define unm unordered_map
// #define int ll
#define ll __int128
const ll mod = 1e9 + 7;
const int MAXN = 2e5 + 5;
const int MAXA = 2e5 + 5;
const ll INF = 1e30;
// vector<int> q[101], dq[101];
int n, m, k;
int b[101][1001], s[101][1001];
ll dp[101][101], d[101][101];
ll c[101][101];
vector<int> ord;
int pos[101];
// void dfs0(int v){
// pos[v] = 1;
// for(int to: q[v]){
// if(pos[to]) continue;
// dfs0(to);
// }
// ord.pb(v);
// }
// void dfs1(int v){
// pos[v] = 1;
// for(int to: dq[v]){
// if(pos[to]) continue;
// dfs1(to);
// }
// }
bool check(int k){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(dp[i][j] != INF) d[i][j] = k * dp[i][j] - c[i][j];
else d[i][j] = INF;
}
}
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] != INF and d[k][j] != INF){
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(i!=j and d[i][j] + d[j][i] <= 0){
return 1;
}
}
}
return 0;
}
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++){
dp[i][j] = INF;
}
dp[i][i] = 0;
}
for(int i=1; i<=m; i++){
int l, r, x;
cin>>l>>r>>x;
dp[l][r] = x;
// q[l].pb(r);
// dq[r].pb(l);
}
for(int k=1; k<=n; k++){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(dp[i][k] != INF and dp[k][j] != INF){
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
}
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
c[i][j] = 0;
for(int d=1; d<=k; d++){
if(s[j][d] != -1 and b[i][d] != -1) c[i][j] = max(c[i][j], (ll)s[j][d] - b[i][d]);
}
}
}
int l=0, r=1e9 + 10;
while(l + 1<r){
int mid=(l + r) / 2;
if(check(mid)) l = mid;
else r = mid;
}
cout<<l<<'\n';
}
signed main(){
ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
while(t--){
solve();
cout<<'\n';
}
}
# | 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... |