Test instructions
Give several power stations, give several consumption stations, and give several forwarding points.
Power stations only generate electricity, consumption stations only consume electricity, the forwarding point is just to turn the power, and then give the conduct electricity ability of each transmission line.
Ask you what the maximum amount of electricity you can get from the consumption station.
Idea: Add a super source point, and a super sink point. Connect the given power station to the super source and connect the consumed war to the super sink. Use EK to find the maximum flow.
There are several places to watch out for templates.
1:start is the first point of the number, last is the final point of the number
Template default Last is M, according to the need to change m to the number of the final point number
#include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include < math.h> #include <queue> #include <stdlib.h> #define INF 0x3f3f3f3fusing namespace Std;int map[1000][1000 ], path[1000], flow[1000], N, m,nc,np,start;int last;queue<int>que;int BFS () {int I, T;while (Que.size ()) Que.pop () ; memset (path, 1, sizeof (path));p Ath[start] = 0;flow[start] = Inf;que.push (start), while (Que.size ()) {int t = Que.front () ; Que.pop (); if (t = = last) break;for (i = 0; I <= n+1; i++) {if (i! = Start && path[i] = =-1 && map[t][i] {Flow[i] = min (flow[t], map[t][i]);p ath[i] = T;que.push (i);}}} if (path[last] = =-1) return-1;else return flow[n+1];} int Liu () {int maxflow = 0, temp, now, pre;while ((temp = BFS ())! =-1) {Maxflow + = Temp;now = Last;while (now! = start) {Pre = Path[now];map[pre][now] = Temp;map[now][pre] + = Temp;now = Pre;}} return maxflow;} Char Temp[20];int main () {int I, j, K, from, To, Cost,u,v,z;while (~scanf ("%d%d%d%d", &(n,&np,&nc,&m)) {memset (map, 0, sizeof (map)), for (i = 0; i < m; i++) {scanf ("%s", temp); sscanf (temp, "(%d,%d )%d ", &u, &v, &z); map[u+1][v+1] + = Z;} for (i = 0; i < NP; i++) {scanf ("%s", temp), sscanf (temp, "(%d)%d", &u, &z); map[0][u+ 1] + = Z;} for (i = 0; i < NC; i++) {scanf ("%s", temp), sscanf (temp, "(%d)%d", &u, &z); map[u+1][n+1] + = Z;} Last=n + 1;start = 0;cout << Liu () << Endl;}}
poj1459, network flow, maximum flow, multi-source point multi-Meeting point