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 for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'
const int MXN = 100;
const ll INF = 1e15;
ll dist[MXN+1][MXN+1], gain[MXN+1][MXN+1], aux[MXN+1][MXN+1];
int main() {
#ifdef shiven
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, k; cin >> n >> m >> k;
vector<vector<vector<ll>>> cost(n, vector<vector<ll>>(k, vector<ll>(2)));
for_(i, 0, n) for_(j, 0, k) cin >> cost[i][j][0] >> cost[i][j][1];
for_(i, 0, n) for_(j, 0, n) dist[i][j] = INF;
for_(i, 0, m) {
int a, b, w; cin >> a >> b >> w;
a -= 1; b -= 1;
dist[a][b] = min(dist[a][b], w);
}
for_(p, 0, n) for_(i, 0, n) for_(j, 0, n) dist[i][j] = min(dist[i][j], dist[i][p]+dist[p][j]);
for_(i, 0, n) for_(j, 0, n) {
for_(p, 0, k) if (cost[i][p][0] != -1 and cost[j][p][1] != -1) gain[i][j] = max(gain[i][j], cost[j][p][1]-cost[i][p][0]);
}
ll lo = 0, hi = 1e13+1, ans = 0;
while (lo < hi) {
ll mid = (lo+hi) / 2;
for_(i, 0, n) for_(j, 0, n) {
if (dist[i][j] != INF) aux[i][j] = mid * dist[i][j] - gain[i][j];
else aux[i][j] = INF;
}
bool valid = false;
for_(p, 0, n) for_(i, 0, n) for_(j, 0, n) aux[i][j] = min(aux[i][j], aux[i][p]+aux[p][j]);
for_(i, 0, n) if (aux[i][i] <= 0) {
valid = true;
break;
}
//cout << mid << " " << valid << endl;
if (valid) {
lo = mid+1; ans = mid;
} else hi = mid;
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
merchant.cpp: In function 'int main()':
merchant.cpp:31:33: error: no matching function for call to 'min(ll&, int&)'
31 | dist[a][b] = min(dist[a][b], w);
| ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
from /usr/include/c++/9/cmath:1927,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
from merchant.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
198 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: template argument deduction/substitution failed:
merchant.cpp:31:33: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
31 | dist[a][b] = min(dist[a][b], w);
| ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
from /usr/include/c++/9/cmath:1927,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
from merchant.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
246 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: template argument deduction/substitution failed:
merchant.cpp:31:33: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
31 | dist[a][b] = min(dist[a][b], w);
| ^
In file included from /usr/include/c++/9/algorithm:62,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
from merchant.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
3444 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: template argument deduction/substitution failed:
merchant.cpp:31:33: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
31 | dist[a][b] = min(dist[a][b], w);
| ^
In file included from /usr/include/c++/9/algorithm:62,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
from merchant.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
3450 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: template argument deduction/substitution failed:
merchant.cpp:31:33: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
31 | dist[a][b] = min(dist[a][b], w);
| ^