Bzoj 1449: [JSOI2009] Team gains (minimum cost maximum flow)

Source: Internet
Author: User

First consider the loss of all the proceeds. Consider each game team to win the increase in earnings, use this to build the map.

--------------------------------------------------------------------------------------------------

#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <iostream>#define REP (i, n) for (int i = 0; i < n; ++i)#define CLR (x, C) memset (x, C, sizeof (x))#define REP (i, n) for (int i = 1; I <= n; ++i)using namespace std;const INT MAXN = 6000 + 5;const int INF = 0X3F3F3F3F;struct Edge {int to, cap, cost;Edge *next, *rev;};edge* pt;edge* head[MAXN];Edge edge[20000];void init () {pt = EDGE;CLR (head, 0);} inline void Add (int u, int v, int d, int w) {pt-to = V;pt, cap = D;pt, cost = w;pt->next = head[u];head[U] = pt++;} inline void Add_edge (int u, int v, int d, int w) {Add (U, V, D, W);Add (V, u, 0,-W);head[u], rev = head[V];Head[v], rev = head[U];}edge* p[MAXN];int d[MAXN], a[MAXN], inq[MAXN];int min_cost (int S, int T) {int cost = 0;for (;;) {CLR (d, INF);d[S] = 0;CLR (inQ, 0);queue< int > Q;a[S] = INF, Q.push (s);While (! Q.empty ()) {int x = Q.front ();Q.pop ();inq[x] = false;For (edge* e = head[x]; e; e = e = next)if (Cap > 0 && d[E, to] > d[x] + E-cost) { int to = e -to;d[to] = d[x] + e -cost;a[to] = min (a[x], e-cap);p[to] = e;if (! inq[to])Q.push (To), inq[to] = true;        }}if (d [T] = = INF) break;Cost + = d[T] * a[T];int x = T;While (x! = S) {p[x], Cap-= a[T];p[X], rev, cap + = a[T];x = p[x], rev, to;}}return cost;}int win[MAXN], lose[MAXN];int c[MAXN], d[MAXN];int cnt[MAXN]; int main () {

init ();int n, m;cin >> n >> m;int s = 0, t = n + m + 1;Rep (i, n) {scanf ("%d%d%d%d", &win[i], &lose[i], &c[i], &d[i]);cnt[I] = 0;}Rep (i, m) {int u, v;scanf ("%d%d", &u, &v);cnt[u]++, cnt[v]++;Add_edge (S, I, 1, 0);Add_edge (i, U + M, 1, 0);Add_edge (i, V + m, 1, 0);}int ans = 0;Rep (i, n) {int x = i + M;lose[i] + = cnt[i];ans + = c[i] * win[i] * win[i] + d[i] * lose[i] * lose[i];While (cnt[i]--) {Add_edge (x, T, 1, 2 * (c[i] * win[i]-d[i] * lose[i]) + c[i] + d[i]);win[i]++;lose[i]--;}}cout << Min_cost (S, T) + ans << "\ n";return 0;}

--------------------------------------------------------------------------------------------------

1449: [JSOI2009] Team earnings time limit: 5 Sec Memory Limit: MB
Submit: $ Solved: 272
[Submit] [Status] [Discuss] Descriptioninputoutput An integer that represents the minimum value of the sum of all the teams in the league. Sample Input3 3
1 0 2 1
1 1 10 1
0 1 3 3
0 S
2 3
3 1
Sample Output43
HINT


Source

Bzoj 1449: [JSOI2009] Team gains (minimum cost maximum flow)

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.