Question: I am too lazy to fight. Lucky Cat contains http: // 163.32.78.26/homework/q10330.htm.
The first network flow question. Each node has a capacity value. Split points are required. Split into I-> I + n edge weights as capacity values
In addition, pay attention to the B-point connection mode: S-Set B
D vertex link mode set D + N-> T Vertex
You can handle other operations.
#include <map>#include <set>#include <list>#include <cmath>#include <ctime>#include <deque>#include <stack>#include <queue>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <climits>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define PI 3.1415926535897932626using namespace std;int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}#define MAXN 250const int INF = 0x3f3f3f3f ;int flow[MAXN][MAXN],c[MAXN][MAXN];int p[MAXN];int N,M,B,D,src,tag;void read(){ memset(c,0,sizeof(c)); src = 0; tag = 2 * N + 1; for (int i = 1; i <= N; i++) { int tmp; scanf("%d",&tmp); c[i][i + N] = tmp; } scanf("%d",&M); for (int i = 1; i <= M; i++) { int u,v,w; scanf("%d%d%d",&u,&v,&w); c[u + N][v] = w; } scanf("%d%d",&B,&D); for (int i = 1; i <= B; i++) { int tmp; scanf("%d",&tmp); c[0][tmp] = INF; } for (int i = 1; i <= D; i++) { int tmp; scanf("%d",&tmp); c[tmp + N][tag] = INF; }}int Edmonds_karp(int src,int tag){ memset(flow,0,sizeof(flow)); int ans = 0; queue<int>q; while (!q.empty()) q.pop(); int a[MAXN]; while (true) { memset(a,0,sizeof(a)); a[src] = INF; q.push(src); while (!q.empty()) { int u = q.front(); q.pop(); for (int v = 0; v <= tag; v++) if (!a[v] && c[u][v] > flow[u][v]) { p[v] = u; q.push(v); a[v] = min(a[u],c[u][v] - flow[u][v]); } } if (a[tag] == 0) break; for (int u = tag; u != src; u = p[u]) { flow[p[u]][u] += a[tag]; flow[u][p[u]] -= a[tag]; } ans += a[tag]; } return ans;}int main(){ //freopen("sample.txt","r",stdin); while (scanf("%d",&N)!=EOF) { read(); printf("%d\n",Edmonds_karp(src,tag)); } return 0;}
Ultraviolet A 10330 Power Transmission