标签:des style blog http color os io strong
Description
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; }
poj1459 Power Network,布布扣,bubuko.com
标签:des style blog http color os io strong
原文地址:http://www.cnblogs.com/6bing/p/3927117.html