This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Freedom will be ours
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1121272678990188431;
const int N = 1e2 + 10, M = 9999, K = 1e3 + 10;
int n, m, k;
ll t[N][N], tmp[N][N], p[N][N], b[N][K], s[N][K];
void floyd(ll g[N][N]){
for(int k = 0; k < n; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
bool check(ll mid){
floyd(tmp);
for(int i = 0; i < n; i++)
if(tmp[i][i] <= 0)
return true;
return false;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
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 < n; i++)
fill(t[i], t[i] + N, INF);
for(int i = 0; i < m; i++){
int v, w, timee;
cin >> v >> w >> timee; v--, w--;
t[v][w] = timee;
}
floyd(t);
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
for(int l = 0; l < k; l++)
if(s[j][k] != -1 and b[i][l] != -1)
p[i][j] = max(p[i][j], s[j][l] - b[i][l]);
ll l = 0, r = 1e9 + 10;
while(r - l > 1){
ll mid = l + (r - l) / 2;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(t[i][j] == INF)
tmp[i][j] = INF;
else tmp[i][j] = mid * t[i][j] - p[i][j];
}
}
if(check(mid)) l = mid;
else r = mid;
}
cout << l << '\n';
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... |