The maximum stream of hdu2883 is used to determine the sap Algorithm for full stream optimization.

Source: Internet
Author: User

This is the title of the Multi-school league in, which is more difficult than that in 10 years. If you have never done hdu3572, we recommend that you do it first. If you have knowledge of the question, you can try again.

This is similar to hdu3572. However, the limit of 1 <= SI <EI <= 1,000,000 allows us to create a graph like hdu3572, which causes too many edges. Thus timeout.

Let's look at others' ideas about http://www.cnblogs.com/wally/archive/2013/05/03/3057066.html discretization.

 

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int n = 2000, M = 1000000, INF = 0x3f3f3f; struct node {int to, next, W;} edge [m]; int head [N], numh [N], H [N], cure [N], pre [N]; // numh: array of statistic heights optimized by gap; H: array of distance labels; cure: Current Arc int ans, TOT; void SAP (INT s, int e, int N) {int flow, U, TMP, neck, I; ans = 0; for (I = 1; I <= N; I ++) cure [I] = head [I]; numh [0] = N; u = s; while (H [s] <n) {If (u = e) {f Low = inf; for (I = s; I! = E; I = edge [cure [I]. to) {If (flow> edge [cure [I]. w) {neck = I; flow = edge [cure [I]. W ;}} for (I = s; I! = E; I = edge [cure [I]. to) {TMP = cure [I]; edge [TMP]. w-= flow; edge [TMP ^ 1]. W + = flow;} ans + = flow; u = neck;} for (I = cure [u]; I! =-1; I = edge [I]. next) if (edge [I]. W & H [u] = H [edge [I]. to] + 1) break; if (I! =-1) {cure [u] = I; Pre [edge [I]. to] = u; u = edge [I]. to;} else {If (0 = -- numh [H [u]) break; // gap optimization cure [u] = head [u]; for (TMP = N, I = head [u]; I! =-1; I = edge [I]. next) if (edge [I]. w) TMP = min (TMP, H [edge [I]. to]); H [u] = TMP + 1; ++ numh [H [u]; If (u! = S) u = pre [u] ;}} void Init () {tot = 0; memset (Head,-1, sizeof (head); memset (PRE, -1, sizeof (pre); memset (H, 0, sizeof (h); memset (numh, 0, sizeof (numh);} void addedge (int I, int J, int W) {edge [tot]. to = J; edge [tot]. W = W; edge [tot]. next = head [I]; head [I] = tot ++; edge [tot]. to = I; edge [tot]. W = 0; edge [tot]. next = head [J]; head [J] = tot ++;} int T [N], St [N], Ed [N]; int main () {// freopen ("test.txt", "r", stdin); int n, m, I, J, K, a, B, c, Sum, S, T; while (scanf ("% d", & N, & M )! = EOF) {Init (); sum = 0; S = n + 1; k = 0; for (I = 1; I <= N; I ++) {scanf ("% d", & St [I], & B, & ED [I], & T); sum + = B * t; addedge (S, I, B * t); t [k ++] = sT [I]; t [k ++] = ed [I];} Sort (t, T + k); j = 0; for (I = 1; I <K; I ++) if (T [J]! = T [I]) T [++ J] = T [I]; k = S + 1 + J; for (I = 1; I <= J; I ++) {addedge (S + I, K, M * (T [I]-T [I-1]); For (t = 1; t <= N; t ++) if (ST [T] <= T [I-1] & ED [T]> = T [I]) addedge (t, I + S, INF);} SAP (S, K, k); If (ANS = sum) printf ("Yes \ n"); else printf ("NO \ n ");} return 0 ;}
View code

 

The maximum stream of hdu2883 is used to determine the sap Algorithm for full stream optimization.

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.