• POJ1273(最大流Augment Path,EK,BFS)


    1273:Drainage Ditches

    时间限制:
    1000ms
    内存限制:
    65536kB
    描述
    Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch. Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network. Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
    输入
    The input includes several cases. For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.
    输出
    For each case, output a single integer, the maximum rate at which water may emptied from the pond.
    样例输入
    5 4 1 2 40 1 4 20 2 4 20 2 3 30 3 4 10
    样例输出
    50

    #include"iostream" #include"queue" #include"cstring" using namespace std; const int MAX=10000001; int cap[201][201];//容量 int flow[201][201];//流量 int d[MAX];//d[i]储存当前路径相应弧最小残量,以弧尾表示弧,有正有负,符号仅表示方向而已 int p[MAX];//父亲节点个数 queue<int> q;//BFS要用 const int s=1; int t;//t有待输入 int f;//储存当前最大流量 void EK() { memset(flow,0,sizeof(flow)); f=0; while(1) { memset(d,0,sizeof(d));//赋值0是可以的 d[s]=MAX;//起点的流量自然是无穷大的 q.push(s); while(!q.empty()) { int u=q.front();q.pop(); for(int v=1;v<=t;v++)//遍历和各节点有连接的邻接弧 if(!d[v]&&cap[u][v]>flow[u][v])//d[v]未曾处理,防止遍历时候重复处理 { p[v]=u;q.push(v); d[v]=(d[u]<cap[u][v]-flow[u][v])?d[u]:(cap[u][v]-flow[u][v]); }//end if }//end while(!q.empty()) if(d[t]==0) break;//若最后一条弧增广量为0,退出while(1) //以下对d[t]!=0的情况进行处理 for(int u=t;u!=s;u=p[u])//从汇点往回走 { flow[p[u]][u]+=d[t]; flow[u][p[u]]-=d[t]; } f+=d[t];//增加当前最大流量 //cout<<"f: "<<f<<endl; }//end while(1) } int main() { int n,m;//弧数和节点数 while(cin>>n>>m) { t=m; int x=0,y=0,z=0; memset(cap,0,sizeof(cap));//赋值0可以用memset while(n--) { cin>>x>>y>>z; cap[x][y]+=z; }
    EK();cout<<f<<endl;//输出结果}//end while(cin>>n>>m) }

  • 相关阅读:
    oracle查看字符集和修改字符集
    oracle11g 使用数据泵导出导入数据
    Oracle 11G在用EXP 导出时,空表不能导出解决
    帮助小伙伴写的组装xml字符串类
    GCD-01
    UITableViewCell-03
    UITableViewCell-02
    iOS代理-03
    UITableViewCell-01
    iOS代理-02
  • 原文地址:https://www.cnblogs.com/lzhitian/p/2329313.html
Copyright © 2020-2023  润新知