HDU-4280 Island Transport (ISAP)

Source: Internet
Author: User

Ask you to send visitors from the east to the west, anyway the side is two-way, no difference

Problem-solving ideas: bare stream

ISAP 8080MS

#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>using namespace STD;#define N 100010#define INF 0x3f3f3f3fstructEdge {intFrom, to, cap, flow; Edge () {} Edge (intFromintTo,intCapintFlow): From, to, Cap (CAP), flow (flow) {}};structISAP {intP[n], Num[n], cur[n], d[n];intT, S, N, M;BOOLVis[n]; vector<int>G[n]; vector<Edge>EdgesvoidInitintN) { This->n = n; for(inti =0; I <= N;            i++) {g[i].clear ();        D[i] = INF;    } edges.clear (); }voidAddedge (intFromintTo,intCAP) {Edges.push_back (Edge (from, to, Cap,0)); Edges.push_back (Edge (to, from,0,0));        m = Edges.size (); G[from].push_back (M-2); G[to].push_back (M-1); }BOOLBFS () {memset(Vis,0,sizeof(VIS)); Queue<int>Q; D[T] =0; VIS[T] =1; Q.push (t); while(! Q.empty ()) {intU = Q.front (); Q.pop (); for(inti =0; I < g[u].size (); i++) {Edge &e = edges[g[u][i] ^1];if(!vis[e.from] && e.cap > E.flow) {Vis[e.from] =true; D[e.from] = D[u] +1;                Q.push (E.from); }            }        }returnVis[s]; }intAugment () {intU = T, flow = INF; while(U! = s)            {Edge &e = edges[p[u]];            flow = min (flow, e.cap-e.flow);        u = edges[p[u]].from; } u = t; while(U! = s)            {Edges[p[u]].flow + = flow; Edges[p[u] ^1].flow-= flow;        u = edges[p[u]].from; }returnFlow }intMaxflow (intSintT) { This->s = s; This->t = t;intFlow =0; BFS ();if(D[s] >= N)return 0;memset(Num,0,sizeof(num));memset(cur,0,sizeof(cur)); for(inti =0; I < n; i++)if(D[i] < INF) num[d[i]]++;intU = s; while(D[s] < n) {if(U = = t)                {Flow + = Augment ();            U = s; }BOOLOK =false; for(inti = Cur[u]; I < g[u].size (); i++) {Edge &e = edges[g[u][i]];if(E.cap > E.flow && d[u] = = D[e.to] +1) {OK =true;                     P[e.to] = G[u][i];                    Cur[u] = i; u = e.to; Break; }            }if(!ok) {intMin = N-1; for(inti =0; I < g[u].size (); i++) {Edge &e = edges[g[u][i]];if(E.cap > E.flow)                min = min (min, d[e.to]); }if(--num[d[u]] = =0) Break; Num[d[u] = Min +1]++; Cur[u] =0;if(U! = s) u = edges[p[u]].from; }        }returnFlow }};isap ISAP;intN, M;voidInit () {scanf("%d%d", &n, &m); Isap.init (n);intx, y;intMin = INF, Max =-inf;intS, t; for(inti =1; I <= N; i++) {scanf("%d%d", &x, &y);if(x <= Min)            {s = i;        Min = x; }if(x >= Max)            {T = i;        Max = x; }    }intU, V, c; for(inti =0; I < m; i++) {scanf("%d%d%d", &u, &v, &c); Isap.        Addedge (U, V, c); Isap.    Addedge (V, U, c); }intAns = isap. Maxflow (S, t);printf("%d\n", ans);}intMain () {intTestscanf("%d", &test); while(test--)    {init (); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU-4280 Island Transport (ISAP)

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.