This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Code written by Talant I.D.
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
const int mod = 1e9+7;
ll mode(ll a) {
a %= mod;
if (a < 0) a += mod;
return a;
}
ll subt(ll a, ll b) {
return mode(mode(a)-mode(b));
}
ll add(ll a, ll b) {
return mode(mode(a)+mode(b));
}
ll mult(ll a, ll b) {
return mode(mode(a)*mode(b));
}
ll binpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b&1) res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
const ll INF = 1e18;
ll buy[103][1003], sell[103][1003];
ll graph[103][103], graph2[103][103], profit[103][103];
int n, K;
void floyd_warshall(ll g[103][103]) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
g[j][k] = min(g[j][k], g[j][i]+g[i][k]);
}
}
}
}
int main() {
do_not_disturb
int m;
cin >> n >> m >> K;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
graph[i][j] = INF;
}
for (int j = 1; j <= K; j++) {
cin >> buy[i][j] >> sell[i][j];
}
}
for (int i = 0; i < m; i++) {
int x, y, w;
cin >> x >> y >> w;
graph[x][y] = w;
}
floyd_warshall(graph);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= K; k++) {
if (buy[i][k] != -1 && sell[j][k] != -1) {
profit[i][j] = max(profit[i][j], sell[j][k]-buy[i][k]);
}
}
}
}
ll l = 1, r = 1e9;
ll ans = 0;
while (l <= r) {
ll mid = (l+r) >> 1ll;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
graph2[i][j] = mid*min(graph[i][j], INF/mid)-profit[i][j];
}
}
floyd_warshall(graph2);
bool flag = 0;
for (int i = 1; i <= n; i++) if (graph2[i][i] <= 0) flag = 1;
if (flag) {
ans = max(ans, mid);
l = mid+1;
}
else {
r = mid-1;
}
}
cout << ans << 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... |