"bzoj4898" [Apio2017] travel floyd+ score Planning +SPFA

Source: Internet
Author: User

Title Description

There are n points, M-bars, and K-commodities. The $i$ point can buy goods $j$ at $b_{ij}$ Price and sell at $s_{ij}$ price. Only one item can be held at any time. Ask for a loop so that the profit/path length (rounded down) is maximized when the initial non-carrying of a product passes through a circle in a certain trading way.

Input

The first line contains 3 positive integers n,m and K, each representing the number of fairs, the number of roads, and the number of commodity types. Next n rows, the line contains 2K integers describing a bazaar bi,1 si,1 bi,2 Si,2...bik si,k. For any 1<=j<=k, the integer and the price of the transaction when the item is bought and sold at the numbered market. If a trade price is-1, it means that the product cannot be traded in this market. Next m line, the line contains 3 integers VP,WP and TP, indicates that there is a market from the number of VP to go to the market number WP minutes spent TP. 1<=n<=100,1<=m<=9900 If in the numbered market I, the item numbered J can be purchased and sold, 0<si,j<=bi,j<=10^9 for the number P (1<=p<=m) The road, guaranteed VP&LT;&GT;WP and 1<=tp<=10^7 does not exist to meet 1<=p<q<=m P,q, make (VP,WP) = (VQ,WQ).

Output

The output contains an integer that represents the most profitable loop profit efficiency, and the answer is rounded down to the integer. If no loop can be profitable, the output is 0.

Sample input

4 5 2
10 9 5 2
6 4 20 15
9 7 10 9
-1-1 16 11
1 2 3
2 3 3
1 4 1
4 3 1
3 1 1

Sample output

2

Exercises

floyd+ Fractional Planning +SPFA

The topic is obviously a model of fractional planning, but if you use a hierarchical chart to simulate the process of buying and selling goods, it will certainly be tle.

We might as well change our mind: Consider a continuous transaction between two points each. The process of buying a product at a and selling it in B.

Then this process must be the shortest way, the trade must be the most profitable commodity (when it is not profitable when obviously not to buy and sell, profit is 0).

Therefore, the Floyd can be used to find the shortest between any two points, and then processed out of any two points between the maximum profit.

You can then find the maximum ratio ring for this graph. Two-point answer, the weight of each side as the maximum profit-the shortest way *mid, if there is a non-negative ring is the establishment of mid, otherwise mid is not established.

Time Complexity $o (N^2k+n^3\log V) $.

#include <queue> #include <cstdio> #include <cstring> #define N 110#define K 1010using namespace std; typedef long Long ll;queue<int> q;int N, Len[n][n], val[n][n], b[n][k], s[n][k], inq[n], Num[n];ll Dis[n];inli NE bool Judge (int mid) {int x, I;while (!q.empty ()) Q.pop (); for (i = 1; I <= n; i + +) dis[i] = inq[i] = Num[i] = 0, q . push (i); while (!q.empty ()) {x = Q.front (), Q.pop (), inq[x] = 0;; for (i = 1; I <= n; i + +) {if (Dis[i] <= dis[x] + val[x][i]-(LL) mid * Len[x][i]) {dis[i] = Dis[x] + val[x][i]-(LL Mid * LEN[X][I];IF (!inq[i]) {if (num[i] = = N) return 1;num[i] + +, inq[i] = 1, Q.push (i);}}} return 0;} int main () {int m, p, I, J, K, X, Y, z, l = 1, r = 0, Mid, ans = 0;scanf ("%d%d%d", &n, &m, &p); fo R (i = 1; I <= n; i + +) for (j = 1; j <= P; j + +) scanf ("%d%d", &b[i][j], &s[i][j]); for (i = 1; I <= n; i + +) for (j = 1; J <= N; j + +) for (k = 1; k <= p; k + +) if (~b[i][k] && ~s[j][k]) val[I][J] = max (Val[i][j], s[j][k]-b[i][k]), memset (Len, 0x3f, sizeof (LEN)), for (i = 1; I <= m; i + +) scanf ("%d%d%d" , &x, &y, &z), len[x][y] = Z, r = max (R, Z), for (k = 1; k <= N; k + +) for (i = 1; I <= n; i + +) F or (j = 1; J <= N; j + +) Len[i][j] = min (Len[i][j], len[i][k] + len[k][j]); while (L <= r) {mid = (L + r) >> 1; if (judge (mid)) ans = Mid, L = mid + 1;else r = mid-1;} printf ("%d\n", ans); return 0;}

"bzoj4898" [Apio2017] travel floyd+ score Planning +SPFA

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.