国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

poj 1459 Power Network(最大流,Edmond Karp)

2019-11-11 07:23:47
字體:
來源:轉載
供稿:網友

題目大意:總公有nodes個節點,有np個發電站,nc個用戶,m條傳輸線路,每個發電站有個最大的發電量,每個用戶有個最大的接受量,問從發電站到用戶最多可以發電多少。 思路:多源點多匯點最大流,添加一個超級源點,一個超級匯點

#include <cstdio>#include <cstring>#include <queue>using std::queue;#define min(a,b) (a<b?a:b)#define INF 99999999;const int MAXN = 105;int r[MAXN][MAXN];int PRe[MAXN];bool vis[MAXN];int nodes,np,nc,m;bool BFS(int s, int t){ memset(vis,false,sizeof(vis)); memset(pre,-1,sizeof(pre)); queue<int> que; pre[s] = s; vis[s] = true; que.push(s); int p; while(!que.empty()) { p = que.front(); que.pop(); for(int i = 1; i <= nodes; ++i) { if(r[p][i] > 0 && !vis[i]) { pre[i] = p; vis[i] = true; if(i == t) return true; que.push(i); } } } return false;}int EK(int s, int t){ int maxflow = 0; int d = INF; while(BFS(s,t)) { d = INF; for(int i = t; i != s; i = pre[i]) d = min(d,r[pre[i]][i]); for(int i = t; i != s; i = pre[i]) { r[pre[i]][i] -= d; r[i][pre[i]] += d; } maxflow += d; } return maxflow;}int main(){ char ch; int u,v,w,s,t; while(scanf("%d %d %d %d",&nodes,&np,&nc,&m) != EOF) { memset(r,0,sizeof(r)); for(int i = 0; i < m; ++i) { scanf(" %c %d %c %d %c %d",&ch,&u,&ch,&v,&ch,&w); r[u+1][v+1] += w; } s = nodes + 1;// 超級源點 t = nodes + 2;//超級匯點 nodes += 2; for(int i = 0; i < np; ++i) { scanf(" %c %d %c %d",&ch,&v,&ch,&w); r[s][v+1] = w; } for(int i = 0; i < nc; ++i) { scanf(" %c %d %c %d",&ch,&u,&ch,&w); r[u+1][t] = w; } printf("%d/n",EK(s,t)); } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 井冈山市| 邹平县| 加查县| 班戈县| 宣恩县| 德庆县| 临沭县| 汉源县| 昭苏县| 望都县| 盘锦市| 逊克县| 铁岭县| 牟定县| 县级市| 甘孜县| 太仓市| 甘孜| 中山市| 当阳市| 枣强县| 滨州市| 天峨县| 延津县| 贡觉县| 黔江区| 洞口县| 阳原县| 瓦房店市| 丰台区| 大埔区| 安宁市| 甘孜县| 扶余县| 察哈| 大邑县| 太原市| 深水埗区| 承德县| 宣武区| 罗城|