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>
using namespace std;
#define log(x) (63^__builtin_clzll(x))
#define endl '\n'
#define all(x) (x).begin() , (x).end()
const int mod = 1e9 + 7, lg = 22 , N = 1e6 + 1;
#define int long long
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> b(n, vector<int>(k)), s(n, vector<int>(k));
for(int i = 0; i < n; ++i)
for(int item = 0; item < k; ++item)
cin >> b[i][item] >> s[i][item];
vector<vector<int>> dis(n, vector<int>(n, 1e9)), maxGain(n, vector<int>(n, 0));
for(int i = 0; i < m; ++i) {
int u, v, len;
cin >> u >> v >> len;
--u, --v;
dis[u][v] = min(dis[u][v], len);
}
for(int mid = 0; mid < n; ++mid)
for(int start = 0; start < n; ++start)
for(int end = 0; end < n; ++end)
dis[start][end] = min(dis[start][end], dis[start][mid] + dis[mid][end]);
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if(dis[i][j] == 1e9) continue;
for(int item = 0; item < k; ++item)
if(s[j][item] != -1 && b[i][item] != -1)
maxGain[i][j] = max(maxGain[i][j], s[j][item] - b[i][item]);
}
}
int l = 0, r = 2e9;
while(l <= r) {
int mid = (l + r) / 2;
vector<vector<long long>> dp(n, vector<long long>(n, -1e18));
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if(dis[i][j] == 1e9) continue;
dp[i][j] = max(dp[i][j], (long long)maxGain[i][j] - (long long)dis[i][j] * mid);
}
}
for(int mid = 0; mid < n; ++mid)
for(int start = 0; start < n; ++start)
for(int end = 0; end < n; ++end)
dp[start][end] = max(dp[start][end], dp[start][mid] + dp[mid][end]);
int ok = 0;
for(int i = 0; i < n; ++i) {
if(dp[i][i] >= 0) ok = 1;
}
if(ok) l = mid + 1;
else r = mid - 1;
}
cout << max(0ll, l - 1) << endl;
return;
}
main() {
ios_base::sync_with_stdio(false);cout.tie(nullptr);cin.tie(nullptr);
int t;
//cin >> t;
t = 1;
while(t--) solve();
return 0;
}
Compilation message (stderr)
merchant.cpp:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
70 | main() {
| ^~~~
# | 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... |