/**
* In the name of Allah
* We are nothing and you're everything
* author: najmuddin
**/
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
#define int ll
const char nl = '\n';
const int N = 10005;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> b(n+1, vector<int> (k+1)), s(n+1, vector<int> (k+1));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j)
cin >> b[i][j] >> s[i][j];
}
queue<tuple<int, int, int, int>> q; // where we, item, profit, path lenght.
for (int i = 1; i <= k; ++i)
q.push({1, i, -b[1][i], 0});
vector<tuple<int, int>> g[n+1]; // to where, lenght
for (int i = 0; i < m; ++i) {
int u, v, w; cin >> u >> v >> w;
g[u].push_back({v, w});
}
int ans = 0;
while (!q.empty()) {
auto [u, it, pr, len] = q.front();
q.pop();
if (u == 1 && len > 0) {
ans = max(ans, pr/len);
continue;
}
int onkiIt = it, onkiPr = pr;
if (u != 1 && it > 0 && s[u][it] > -1) { // need to sell the item.
pr += s[u][it];
it = -1;
}
for (auto [i, w]: g[u]) {
if (u != 1 && pr != onkiPr)q.push({i, -1, pr, len+w});
q.push({i, onkiIt, onkiPr, len+w});
}
}
cout << ans;
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... |