1 #include<stdio.h>
2 #include<string.h>
3 #include<algorithm>
4 #include<queue>
5 #define inf 0x3f3f3f3f
6 using namespace std;
7 int flow[20][20],cap[20][20],a[20],p[20],n;
8 int ek()
9 {
10 queue<int>q;
11 while (!q.empty()) q.pop();
12 memset(flow,0,sizeof(flow));
13 int f=0,s=1,t=n;
14 while (1)
15 {
16 memset(a,0,sizeof(a));
17 a[s]=inf; q.push(s);
18 while (!q.empty())
19 {
20 int u=q.front(); q.pop();
21 for (int v=1;v<=n;v++)
22 if (!a[v]&&cap[u][v]>flow[u][v])
23 {
24 p[v]=u; q.push(v);
25 if (a[u]<cap[u][v]-flow[u][v]) a[v]=a[u];
26 else a[v]=cap[u][v]-flow[u][v];
27 }
28 }
29 if (a[t]==0) break;
30 for (int u=t;u!=s;u=p[u])
31 {
32 flow[p[u]][u]+=a[t];
33 flow[u][p[u]]-=a[t];
34 }
35 f+=a[t];
36 }
37 return f;
38 }
39 int main()
40 {
41 int T,t,m,q,p,v;
42 scanf("%d",&T);
43 for (t=1;t<=T;t++)
44 {
45 scanf("%d%d",&n,&m);
46 memset(cap,0,sizeof(cap));
47 while (m--)
48 {
49 scanf("%d%d%d",&p,&q,&v);
50 cap[p][q]+=v;
51 }
52 printf("Case %d: %d\n",t,ek());
53 }
54 }
http://acm.hdu.edu.cn/showproblem.php?pid=3549