Submission #165450

#TimeUsernameProblemLanguageResultExecution timeMemory
165450fedoseevtimofeyTravelling Merchant (APIO17_merchant)C++14
100 / 100
130 ms3456 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int Inf = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n, m, k; cin >> n >> m >> k; vector <vector <int>> s(n, vector <int> (k)), b(n, vector <int> (k)); for (int i = 0; i < n; ++i) { for (int j = 0; j < k; ++j) { cin >> b[i][j] >> s[i][j]; } } vector <vector <int>> d(n, vector <int> (n, Inf)); for (int i = 0; i < m; ++i) { int u, v, x; cin >> u >> v >> x; --u, --v; d[u][v] = x; } 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]); } } } vector <vector <int>> best(n, vector <int> (n, 0)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { for (int id = 0; id < k; ++id) { if (s[j][id] != -1 && b[i][id] != -1) best[i][j] = max(best[i][j], s[j][id] - b[i][id]); } } } vector <vector <ll>> w(n, vector <ll> (n)); int l = 0, r = 1e9 + 7; while (r - l > 1) { int m = (l + r) >> 1; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { w[i][j] = best[i][j] - (ll)m * d[i][j]; } } for (int k = 0; k < n; ++k) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { w[i][j] = max(w[i][j], w[i][k] + w[k][j]); } } } bool fl = false; for (int i = 0; i < n; ++i) { if (w[i][i] >= 0) fl = true; } if (fl) 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...