poj1459 Power Network
Description
An example is in figure 1. The label x/y of power station u shows that p(u)=x and p max(u)=y. The label x/y of consumer u shows that c(u)=x and cmax(u)=y. The label x/y of power transport line (u,v) shows that l(u,v)=x and l max(u,v)=y. The power consumed is Con=6. Notice that there are other possible states of the network but the value of Con cannot exceed 6.
Input
Output
Sample Input
2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 7 2 3 13 (0,0)1 (0,1)2 (0,2)5 (1,0)1 (1,2)8 (2,3)1 (2,4)7 (3,5)2 (3,6)5 (4,2)7 (4,3)5 (4,5)1 (6,0)5 (0)5 (1)2 (3)2 (4)1 (5)4
Sample Output
15 6
Hint
#include<stdio.h> #include<queue> #include<string.h> #define MAXN 1000 #define INF 1<<28 int cap[MAXN][MAXN], vis[MAXN], pre[MAXN], maxflow[MAXN]; using namespace std; int n, npow, ncon, m; void bfs() { queue<int>q; int i, Maxflow, u, v; Maxflow = 0; while(1) { memset(vis, 0, sizeof(vis)); memset(pre, 0, sizeof(pre)); memset(maxflow, 0, sizeof(maxflow)); maxflow[n] = INF; q.push(n); vis[n] = 1; while(!q.empty()) { u = q.front(); q.pop(); for(v=0; v<=n+1; v++){ if(!vis[v] && cap[u][v]>0){ vis[v] = 1; pre[v] = u; q.push(v); maxflow[v] = maxflow[u]<cap[u][v]?maxflow[u]:cap[u][v]; } } } if(!maxflow[n+1]) break; for(i=n+1; i!=n; i=pre[i]) { cap[pre[i]][i] -= maxflow[n+1]; cap[i][pre[i]] += maxflow[n+1]; } Maxflow += maxflow[n+1]; } printf("%d\n", Maxflow); } int main() { int i, u, v, c; while(~scanf("%d %d %d %d", &n, &npow, &ncon, &m)) { memset(cap, 0, sizeof(cap)); for(i=0; i<m; i++){ scanf(" (%d,%d)", &u, &v); scanf("%d", &c); cap[u][v] += c; } for(i=0; i<npow; i++){ scanf(" (%d)", &u); scanf("%d", &c); cap[n][u] += c; } for(i=0; i<ncon; i++){ scanf(" (%d)", &v); scanf("%d", &c); cap[v][n+1] += c; } bfs(); } return 0; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。