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 <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <bits/stdc++.h>
#define initrand mt19937 mt_rand(time(0));
#define rand mt_rand()
#define int long long
#define INF 10000000000000000
using namespace std;
#define mid(l, u) ((l+u)/2)
//#define cin fin
//#define cout fout
signed main(){
int n, m, k;
cin>>n>>m>>k;
int mat[n][n], p[n][n];
int b[n][k], s[n][k];
for(int i =0;i<n;i++){
for(int j =0 ;j<n;j++){
mat[i][j] = INF;
p[i][j] = INF;
}
p[i][i] = 0;
mat[i][i] = 0;
}
for(int i =0 ;i<n;i++){
for(int j =0 ;j<k;j++){
cin>>b[i][j]>>s[i][j];
}
}
for(int i = 0;i<m;i++){
int u, v, t;
cin>>u>>v>>t;
mat[u-1][v-1] = t;
}
for(int x = 0;x<n;x++){
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
mat[i][j] = min(mat[i][j], mat[i][x] + mat[x][j]);
}
for(int j = 0;j<k;j++){
p[x][i] = 0;
if(s[i][j]!=-1 && b[x][j]!=-1) p[x][i] = max(p[x][i], s[i][j] - b[x][j]);
}
}
}
/*for(int i =0 ;i<n;i++){
for(int j = 0;j<n;j++){
cout<<"distance from "<<i<<" to "<<j<<" is "<<mat[i][j]<<endl;
}
}*/
int l = 1;
int u = 1e12;
int ans = 0;
while(l<=u){
int r = mid(l, u);
bool found = false;
int adj[n][n];
for(int i =0 ;i<n;i++){
for(int j = 0;j<n;j++){
adj[i][j] = INF;
adj[i][j] = min(adj[i][j], -(p[i][j] - r*mat[i][j]));
}
}
for(int x = 0;x<n;x++){
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
adj[i][j] = min(adj[i][j], adj[i][x] + adj[x][j]);
}
}
}
for(int i = 0;i<n;i++){
for(int j =0;j<n;j++){
if(i==j) continue;
if((adj[i][j] + adj[j][i]) <= 0){
//cout<<i<<" "<<j<<" "<<adj[i][j]<<" "<<j<<" "<<i<<" "<<adj[j][i]<<endl;
found = true;
}
}
}
//cout<<r<<" "<<found<<endl;
if(found){
ans = max(ans, r);
l = r + 1;
}
else{
u = r-1;
}
}
cout<<ans<<endl;
}
/*
4 5 2
10 9 5 2
6 4 20 15
9 7 10 9
-1 -1 16 11
1 2 3
2 3 3
1 4 1
4 3 1
3 1 1
*/
# | 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... |