Http://acm.hdu.edu.cn/showproblem.php? PID = 1532 ek

Source: Internet
Author: User

# Include <algorithm> <br/> # include <cstdio> <br/> # include <iostream> <br/> # include <queue> <br/> # include <cstring> <br/> using namespace STD; <br/> const int n= 205; <br/> struct node {<br/> int C, end; <br/> int next; <br/>} e [2 * n]; <br/> int pre [N]; // record the precursor <br/> int head [N]; <br/> int path [N]; // record path <br/> int ne, NV; // edge point <br/> int EK (INT start, int end) {<br/> int maxflow = 0; <br/> while (true) {<br /> Memset (PRE,-1, sizeof (pre); <br/> queue <int> q; <br/> q. push (start); <br/> while (! Q. empty () {<br/> int u = Q. front (); <br/> q. pop (); <br/> for (INT I = head [u]; I! =-1; I = E [I]. next) {<br/> int v = E [I]. end; <br/> If (pre [v] =-1 & E [I]. c> 0) {<br/> pre [v] = u; <br/> q. push (V); <br/> path [v] = I; <br/>}< br/> If (pre [end]! =-1) <br/> break; // reaches the settlement point and jumps out of BFS <br/>}< br/> If (pre [end] =-1) <br/> break; // No augmented path, jumps out of a Large Loop <br/> int mindelta =-1; <br/> for (INT v = end; V! = Start; V = pre [v]) {<br/> If (mindelta =-1 | E [path [v]. c <mindelta) {<br/> mindelta = E [path [v]. c; <br/>}// find the smallest Delta <br/>}< br/> for (INT v = end; V! = Start; V = pre [v]) {<br/> E [path [v]. c-= mindelta; <br/> // traffic minus delta <br/> E [path [v] ^ 1]. c + = mindelta; <br/> // + regret value <br/>}< br/> maxflow + = mindelta; <br/>}< br/> return maxflow; <br/>}< br/> void insert (int u, int V, int C, int cc = 0) {<br/> E [NE]. C = C; E [NE]. end = V; <br/> E [NE]. next = head [u]; head [u] = ne ++; <br/> E [NE]. C = cc; E [NE]. end = u; <br/> E [NE]. next = head [v]; head [v] = ne ++; <br/>}< br /> Int main () {</P> <p> int n, m; <br/> while (scanf ("% d", & N, & M )! = EOF) {<br/> Ne = 0; <br/> NV = 205; <br/> for (INT I = 0; I <n; I ++) <br/> head [I] =-1; <br/> while (n --) {<br/> int U, V, C; <br/> scanf ("% d", & U, & V, & C); <br/> insert (u, v, C, 0 ); <br/>}< br/> printf ("% d/N", EK (1, m); <br/>}< br/>} 

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.