Bzoj 3931 Cqoi 2015 network throughput shortest circuit + maximum flow

Source: Internet
Author: User

Main topic

Gives an no-map to find the maximum flow of a graph of all the shortest circuits from 1 to n on this graph.

Ideas

Want to let everybody stack template also not take so lazy.
Remember to open long long on the line.

CODE
#define _crt_secure_no_warnings#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAXP 10010#define Maxe 1000010#define S 0#define T (MAXP-1)#define INF 0X3F3F3F3F3F3F3F3FLLusing namespace STD;structmaxflow{intHEAD[MAXP], total;int_next[maxe], aim[maxe];Long LongFlow[maxe];intDEEP[MAXP]; Maxflow (): Total (1) {}voidADD (intXintYLong Longf) {_next[++total] = head[x];        Aim[total] = y;        Flow[total] = f;    HEAD[X] = total; }voidInsert (intXintYLong Longf) {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; }Long LongDinic (intXLong Longf) {if(x = = T)returnFLong Longtemp = f; for(inti = head[x]; I i = _next[i])if(Flow[i] && deep[aim[i]] = = Deep[x] +1&& temp) {Long Longaway = 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;structedge{intX, y, Z;voidRead () {scanf("%d%d%d", &x, &y, &z); }}edge[maxe];intpoints, edges;intHEAD[MAXP], total;int_next[maxe], aim[maxe];Long LongLength[maxe];inline voidADD (intXintYLong LongLen) {_next[++total] = head[x];    Aim[total] = y;    Length[total] = len; HEAD[X] = total;}Long LongL1[MAXP], L2[MAXP];BOOLV[MAXP];voidDijkstra (intStartLong LongF[]) {memset(V,false,sizeof(v)); F[start] =0; for(inti =1; I <= points; ++i) {Long LongMin_length = INF;intP for(intj =1; J <= points; ++J)if(!v[j] && f[j] < min_length) Min_length = F[j], p = j; V[P] =true; for(intj = Head[p]; J j = _next[j])if(!v[aim[j]]) f[aim[j] [min (F[aim[j]], f[p] + length[j]); }}intMain () {Cin>> points >> edges; for(inti =1; I <= edges; ++i) {Edge[i].        Read ();        ADD (edge[i].x, Edge[i].y, edge[i].z);    ADD (Edge[i].y, edge[i].x, edge[i].z); } for(intX, i =1; I <= points; ++i) {scanf("%d", &x); Solver. Insert (i <<1, I <<1|1, (i = =1|| i = = points)?    INF:X); }memset(L1,0x3f,sizeof(L1));memset(L2,0x3f,sizeof(L2)); Dijkstra (1, L1); Dijkstra (points, L2);Long LongMin_length = l2[1]; for(inti =1; I <= edges; ++i) {if(l1[edge[i].x] + l2[edge[i].y] + edge[i].z = = min_length) solver. Insert (edge[i].x <<1|1, Edge[i].y <<1, INF);if(l2[edge[i].x] + l1[edge[i].x] + edge[i].z = = min_length) solver. Insert (Edge[i].y <<1|1, edge[i].x <<1, INF); } solver. Insert (S,2, INF); Solver. Insert (Points <<1|1, T, INF);Long LongMax_flow =0; while(Solver. BFS ()) Max_flow + = Solver. Dinic (S, INF);cout<< Max_flow << Endl;return 0;}

Bzoj 3931 Cqoi 2015 network throughput shortest circuit + maximum flow

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.