Bzoj 1570 Jsoi Travel Network flow of Blue Mary

Source: Internet
Author: User

Main topic

Given a graph, each person can only do once a day plane. Now give the starting point, the end point, and the number of people to go, as well as the number of restrictions on each route, and ask at least how many days the slowest person reaches the finish line.

Ideas

is obviously the network flow model, as to how to verify, in fact, even two points are not used, enumerate the minimum number of days, and then each add a layer of edge to verify on the line.

CODE
#define _crt_secure_no_warnings#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 100010#define Maxe 1000010#define S 0#define SS (MAX-2)#define T (MAX-1)#define INF 0x3f3f3f3fusing namespace STD;structedge{intX, y, Z;voidRead () {scanf("%d%d%d", &x, &y, &z); }}edge[maxe];structmaxflow{intHead[max], total;int_next[maxe], Aim[maxe], flow[maxe];intBackup_flow[maxe];intDeep[maxe]; Maxflow (): Total (1) {}voidADD (intXintYintf) {_next[++total] = head[x];        Aim[total] = y;        Backup_flow[total] = f;    HEAD[X] = total; }voidInsert (intXintYintf) {Add (x, Y, F); Add (y, X,0); }BOOLBFS () {Static  Queue<int>Q while(!q.empty ()) Q.pop ();memset(Deep,0,sizeof(deep)); Deep[s] =1; Q.push (S); while(!q.empty ()) {intx = Q.front (); Q.pop (); for(inti = head[x]; I i = _next[i])if(Flow[i] &&!deep[aim[i]) {Deep[aim[i]] = deep[x] +1; Q.push (Aim[i]);if(Aim[i] = = T)return true; }        }return false; }intDinic (intXintf) {if(x = = T)returnFinttemp = f; for(inti = head[x]; I i = _next[i])if(Flow[i] && temp && deep[aim[i]] = = Deep[x] +1) {intaway = Dinic (Aim[i], min (flow[i], temp));if(!away) deep[aim[i]] =0;            Flow[i]-= away; Flow[i ^1] + = away;        Temp-= away; }returnF-temp; }}solver;intPoints, edges, persons;intMain () {Cin>> points >> edges >> persons; for(inti =1; I <= edges; ++i) Edge[i].    Read (); Solver. Insert (S, SS, persons);intnow =0; for(inti =1;; ++i) { for(intj =1; J <= Edges; ++J) Solver.        Insert (now + edge[j].x, now + edge[j].y + points, edge[j].z); Solver.        Insert (now + points + points, T, INF); Solver. Insert (SS, now +1, INF);memcpy(Solver.flow, Solver.backup_flow,sizeof(Solver.flow));intMax_flow =0; while(Solver. BFS ()) Max_flow + = Solver. Dinic (S, INF);if(Max_flow = = persons) {cout<< i << Endl;return 0;    } now + = points; }return 0;}

Bzoj 1570 Jsoi Travel Network flow of Blue Mary

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.