Submission #745308

#TimeUsernameProblemLanguageResultExecution timeMemory
745308gnuTravelling Merchant (APIO17_merchant)C++14
100 / 100
90 ms4556 KiB
#include <iostream> #include <vector> using namespace std; // APIO 2017 Merchant vector<vector<long long>> d, max_delta, d1; struct node { long long v, w; }; vector<vector<node>> gp; vector<vector<long long>> b, s; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; gp = vector<vector<node>>(n); d = vector<vector<long long>>(n, vector<long long> (n, 1e18)); b = s = vector<vector<long long>>(n, vector<long long>(k)); for (int i = 0; i < n; ++i) { for (int j = 0; j < k; ++j) { cin >> b[i][j] >> s[i][j]; } } vector<pair<int, int>> edges; for (int i = 0; i < m; ++i) { int u, v, w; cin >> u >> v >> w; --u, --v; gp[u].push_back({ v, w }); d[u][v] = w; edges.push_back({ u, v }); } //return 0; for (int k = 0; k < n; ++k) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } max_delta = vector<vector<long long>>(n, vector<long long>(n)); for (int p = 0; p < k; ++p) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (s[j][p] == -1 || b[i][p] == -1) continue; max_delta[i][j] = max(max_delta[i][j], s[j][p] - b[i][p]); } } } // p/t >= m //p >= t*m; // p - t*m >= 0 d1 = vector<vector<long long>> (n, vector<long long>(n, -1e18)); long long l = 0, r = 1e11; while (l + 1 < r) { long long m = (l + r) / 2; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int u = i; int v = j; long long p = 1e18 / m; d1[u][v] = max_delta[u][v] - m * min(p, d[u][v]); } } for (int k = 0; k < n; ++k) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { d1[i][j] = max(d1[i][j], d1[i][k] + d1[k][j]); } } } bool f = 0; for (int i = 0; i < n; ++i) if (d1[i][i] >= 0) f = 1; d1 = vector<vector<long long>>(n, vector<long long>(n, -1e18)); if (f) l = m; else r = m; } cout << l << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...