HDU 3549 Flow Problem (directed edge network Stream)

Source: Internet
Author: User

Question: n under T test data. m indicates n points. m points are directed to the weighted edge. m points are asked: how many test boards are tested from 1 to n maximum streams, I didn't have any idea. I used dinic below. I didn't consider reverse arc debug for a long time. I provided a large batch of test data.

# Include <iostream> # include <string> # include <cstring> # include <algorithm> # include <cstdio> # include <cctype> # include <queue> # include <stdlib. h> # include <cstdlib> # include <math. h> # include <set> # include <vector> # define inf 100000000 # define eps 1e-8 # define N 205 # define M 1050 # define ll intusing namespace std; inline ll Max (ll a, ll B) {return a> B? A: B;} inline ll Min (ll a, ll B) {return a <B? A: B;} // M indicates the number of edges. N indicates the number of points. 1-N // M indicates the number of edges. N indicates the number of points. from 1-nstruct Edge {int from, to, flow, cap, nex;} edge [M * 2]; // bidirectional edge. Note that the RE template combines the edge of the same starting vertex instead of the int head [N] And edgenum; // initialize two-1 and 0 void addedge (int u, int v, int cap) {// apply reverse arc Edge E = {u, v, 0, cap, head [u]}; edge [edgenum] = E; head [u] = edgenum ++; Edge E2 = {v, u, 0, 0, head [v]}; // if the cap is a unidirectional edge, it must be 0 edge [edgenum] = E2; head [v] = edgenum ++;} int dis [N], cur [N]; // The distance from the starting point. cur [I] indicates that the edge optimization being considered by the I point is not considered. The used vertex is initialized to hea. Dbool vis [N]; bool BFS (int Start, int End) {memset (vis, 0, sizeof (vis); memset (dis,-1, sizeof (dis); queue <int> Q; while (! Q. empty () Q. pop (); Q. push (Start); dis [Start] = 0; vis [Start] = 1; while (! Q. empty () {int u = Q. front (); Q. pop (); for (int I = head [u]; I! =-1; I = edge [I]. nex) {Edge E = edge [I]; if (! Vis [E. to] & E. cap> E. flow) {vis [E. to] = 1; dis [E. to] = dis [u] + 1; if (E. to = End) return true; Q. push (E. to) ;}}return false;} int DFS (int x, int a, int End) {// The inbound traffic to x is aif (x = End | a = 0) return a; int flow = 0, f; for (int & I = cur [x]; I! =-1; I = edge [I]. nex) {Edge & E = edge [I]; if (dis [x] + 1 = dis [E. to] & (f = DFS (E. to, Min (a, E. cap-E.flow), End)> 0) {E. flow + = f; edge [I ^ 1]. flow-= f; // flow + = f; a-= f; if (a = 0) break;} return flow ;} int Maxflow (int Start, int End) {int flow = 0; while (BFS (Start, End) {memcpy (cur, head, sizeof (head )); // copy the head array to flow + = DFS (Start, inf, End);} return flow;} int main () {int T, Cas = 1, n, m, I, a, B, c; scanf ("% d", & T); while (T --) {memset (head,-1, sizeof (head )); edgenum = 0; scanf ("% d", & n, & m); while (m --) {scanf ("% d", &, & B, & c); addedge (a, B, c);} printf ("Case % d: % d \ n", Cas ++, Maxflow (1, n);} return 0 ;} /* 993 21 2 12 3 13 31 2 12 3 11 3 13 21 3 21 3 53 21 2 4561 2 564313 3 3 1001 1 1001 1 10011 151 2 1 3 11 4 12 5 12 6 13 7 13 8 14 9 14 10 15 16 11 17 11 11 11 19 11 11 110 11 111 151 2 21 3 21 4 22 5 12 6 13 7 13 8 14 9 14 10 15 11 16 11 17 11 11 19 11 110 11 111 151 2 21 3 11 4 22 5 12 6 13 7 13 8 14 9 14 10 15 11 16 11 17 11 18 11 19 11 110 11 12 02 11 2 46514 41 2 102 1 52 4 201 3 34 51 2 102 1 52 4 201 3 33 4 19 101 5 22 4 62 3 4 1 2 93 9 55 9 42 3 14 2 16 7 13 24 41 2 101 3 23 4 12 4 14 41 2 11 3 13 4 102 4 10ans: 1270100365046511011722 */

 


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.