POJ 1459 Power Network)
This is actually a nonsense. I also gave an illustration, which is actually misleading.
For an electric power network, there are power stations, power supplies, and transmission lines. There are limits on power stations, power grids, and transmission lines. Therefore, there is a network flow problem. First, the power supply line and limit are given, and then the power supply end is given.
Because it is a multi-source site (multiple power stations) and a multi-sink point (multiple electricity producers), super source processing is required.
Most of them are super sources. If there is a source that connects to all source points (power stations), and its line capacity is the limit of power stations, the power stations can be treated as common points. Assume that a super settlement point connects all the settlement points (electricity supplier) to this super settlement point. The capacity of the line is the limit of the electricity supplier, and then it becomes a single source point, the maximum flow problem of a single sink. You can solve the problem by using dinic.
# Include
# Include
# Include
# Include
# Include
# Include # define MAX 999999 using namespace std; int map _ [200] [200]; int dis [200]; int bfs (int s, int t) {int now; memset (dis,-1, sizeof (dis); dis [s] = 0; queue
Que; que. push (s); while (! Que. empty () {now = que. front (); que. pop (); for (int I = 0; I <= t; I ++) if (dis [I] =-1 & map _ [now] [I]> 0) {dis [I] = dis [now] + 1; que. push (I) ;}} if (dis [t]! =-1) return 1; return 0;} int dinic (int s, int t, int x) {if (s = t) return x; int tmp = x; for (int I = 0; I <= t; I ++) {if (dis [I] = dis [s] + 1 & map _ [s] [I]> 0) {int imin = dinic (I, t, min (map _ [s] [I], x); map _ [s] [I]-= imin; map _ [I] [s] + = imin; x-= imin ;}} return tmp-x;} int main () {int n, np, nc, m; while (~ Scanf (% d, & n, & np, & nc, & m) {int I, k; int u, v, c; memset (map _, 0, sizeof (map _); for (I = 0; I <m; I ++) {scanf (% d, % d) % d, & u, & v, & c); map _ [u + 1] [v + 1] + = c; // 0 is a super source, other points move back} for (I = 0; I <np; I ++) {scanf (% d) % d, & v, & c ); map _ [0] [v + 1] + = c;} for (I = 0; I <nc; I ++) {scanf (% d) % d, & u, & c); map _ [u + 1] [n + 1] + = c;} int ans = 0; while (bfs (0, n + 1 )) ans + = dinic (0, n + 1, MAX); printf (% d, ans);} return 0 ;}
Don't forget your mind, always have