This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// APIO17_merchant
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'
#define MAXN 120
#define MAXK 1020
#define MAXE 9950
int n, m, k;
int b[MAXN][MAXK], s[MAXN][MAXK];
int dist[MAXN][MAXN];
int prof[MAXN][MAXN];
ll nd[MAXN][MAXN];
bool check(int x)
{
FOR(i, 1, n + 1) FOR(j, 1, n + 1) nd[i][j] = x * (ll)dist[i][j] - prof[i][j];
FOR(i, 1, n + 1) nd[i][i] = LINF;
FOR(k, 1, n + 1) FOR(i, 1, n + 1) FOR(j, 1, n + 1) nd[i][j] = min(nd[i][j], nd[i][k] + nd[k][j]);
FOR(i, 1, n + 1) if (nd[i][i] <= 0) return true;
return false;
}
int32_t main(void)
{
fast_io;
cin >> n >> m >> k;
FOR(i, 1, n + 1) FOR(j, 0, k) cin >> b[i][j] >> s[i][j];
FOR(i, 0, MAXN) fill(dist[i], dist[i] + MAXN, INF);
FOR(i, 0, m)
{
int x, y, w;
cin >> x >> y >> w;
dist[x][y] = w;
}
FOR(k, 1, n + 1) FOR(i, 1, n + 1) FOR(j, 1, n + 1) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
FOR(i, 1, n + 1)
{
FOR(j, 1, n + 1)
{
if (dist[i][j] >= INF) continue;
FOR(o, 0, k) if (s[j][o] > 0 && b[i][o] > 0)
prof[i][j] = max(prof[i][j], s[j][o] - b[i][o]);
}
}
int l = 0, r = INF;
while (r - l > 1)
{
int mid = (r + l) / 2;
if (check(mid)) l = mid;
else r = mid;
}
cout << l << endl;
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... |