This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
#include "bits/stdc++.h"
using namespace std;
#define li long long
#define ld long double
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define em emplace
#define ob pop_back
#define om pop
#define of pop_front
#define fori(i, a, b) for(int i = (int) (a); i <= (int) (b); ++i)
#define ford(i, a, b) for(int i = (int) (a); i >= (int) (b); --i)
#define forIT(it, begin, end) for(__typeof(end) it = (begin) + ((begin) > (end)); it != (end) - ((begin) > (end)); it += 1 - 2 * ((begin) > (end)))
#define b_e(x) begin(x), end(x)
#define sz(x) ((int)(x).size())
#define bitc __builtin_popcountll
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define endl '\n'
#define sp ' '
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void solve();
signed main() {
// freopen("test.inp","r",stdin);
// freopen("test.out","w",stdout);
fastio;
int tc = 1;
fori(test, 1, tc) {
solve();
}
return 0;
}
#define int long long
const ld pi = 4 * atan(1.0), eps = 1e-9;
const int maxn = 105, maxk =1004, inf = LLONG_MAX / 1000ll;
int n, m, tp;
int s[maxn][maxk], b[maxn][maxk];
int dis[maxn][maxn];
int pro[maxn][maxn];
int step[maxn][maxn];
int sum[maxn][maxn];
void solve() {
cin >> n >> m >> tp;
fori(i, 1, n) {
fori(j, 1, n) {
if(i == j) dis[i][j] = 0;
else dis[i][j] = inf;
}
}
fori(i,1,n) {
fori(k, 1, tp) {
cin >> b[i][k] >> s[i][k];
if(b[i][k] == -1) b[i][k] = inf;
if(s[i][k] == -1) s[i][k] = -inf;
}
}
fori(i, 1, m) {
int u, v, w; cin >> u >> v >> w;
dis[u][v] = min(dis[u][v], w);
}
fori(k, 1, n) {
fori(i, 1, n) {
fori(j, 1, n) {
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
}
fori(i, 1, n) fori(j, 1, n) pro[i][j] = -inf;
fori(i, 1, n) {
fori(j, 1, n) {
fori(k, 1, tp) {
pro[i][j] = max(pro[i][j], s[j][k] - b[i][k]);
// cout << i << sp << j << sp << pro[i][j] << endl;
}
}
}
int lo = 0;
int hi = inf;
while(lo < hi) {
int mi = lo + hi + 1 >> 1;
int ratio = mi;
fori(i, 1, n) {
fori(j, 1, n) {
step[i][j] = -inf;
fori(k, 1, n) {
step[i][j] = max(step[i][j], - ratio * (dis[i][k] + dis[k][j]) + pro[i][k]);
}
// if(ratio < 10) cout << ratio << sp << i << sp << j << sp << step[i][j] << endl;
}
}
fori(i, 1, n) fori(j, 1, n) {
if(i != j) sum[i][j] = step[i][j];
else sum[i][j] = -inf;
}
fori(k, 1, n) fori(i, 1, n) fori(j, 1, n) {
sum[i][j] = max(sum[i][j], sum[i][k] + sum[k][j]);
}
bool ok = 0; fori(i, 1, n) if(sum[i][i] >= 0) ok = 1;
if(ok) lo = mi;
else hi = mi - 1;
}
cout << lo;
}
Compilation message (stderr)
merchant.cpp: In function 'void solve()':
merchant.cpp:104:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
104 | int mi = lo + hi + 1 >> 1;
| ~~~~~~~~^~~
# | 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... |