2013
12-12

# Drainage Ditches

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 <string.h>
using namespace std;

#include <queue>
#define min(x,y) (x<y?x:y)
const int inf = 1000000000;
const int maxn = 210;
int cap[maxn][maxn];
int n,m;
int s,t;
int flow[maxn][maxn],d[maxn],parent[maxn],maxflow;

void Edmonds_Karp(int s,int t,int nnum)
{
maxflow = 0;
memset(flow,0,sizeof(flow));
memset(parent,0,sizeof(parent));
while(true)
{
memset(d,0,sizeof(d));
queue<int>que;
d[s]=inf;
que.push(s);
while(!que.empty())             //BFS寻找增广路
{
int u = que.front();
que.pop();
for(int v=0; v<nnum; ++v)
{
if(!d[v] && cap[u][v]>flow[u][v])            //找到新结点v
{
parent[v] = u;                           //记录v的父亲，并参加FIFO队列
que.push(v);
d[v] = min(d[u],cap[u][v]-flow[u][v]);  //s-v路径上的最小残量
}
}
}
if(0==d[t])                    //找不到，则当前流已经是最大流
break;
for(int u=t;u!=s;u=parent[u])  //从汇点往回走
{
flow[parent[u]][u]+=d[t];  //更新正向流
flow[u][parent[u]]-=d[t];  //更新反向流
}
maxflow += d[t];                 //更新从s流出的总流量
}
}
int main()
{
while(cin>>n>>m)
{
memset(cap,0,sizeof(cap));
while(n--)
{
int temps,tempe,c;
cin>>temps>>tempe>>c;
cap[temps-1][tempe-1]+=c;   //处理惩罚重边
}
Edmonds_Karp(0,m-1,m);
cout<<maxflow<<endl;
}
return 0;
}

1. 第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。

2. 我没看懂题目
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
我觉得第一个应该是5 6 -1 5 4 输出是19 5 4
第二个是7 0 6 -1 1 -6 7输出是14 7 7
不知道题目例子是怎么得出来的