直接模板
#include<iostream>
using namespace std;
const int maxn=20;
const int inf=0x3f3f3f3f;
struct EK
{
int cap[maxn][maxn];
int flow[maxn][maxn];
int n;
void init(int n)
{
this->n=n;
memset(cap,0,sizeof(cap));
}
void addcap(int i,int j,int val)
{
cap[i][j]+=val;
}
int solve(int source,int sink)
{
if(source==sink) return inf;
static int que[maxn],pre[maxn],d[maxn];
int p,q,t;
memset(flow,0,sizeof(flow));
while(1)
{
memset(pre,255,sizeof(pre));
d[source]=inf;
p=q=0;
que[q++]=source;
while(p<q&&pre[sink]==-1)
{
t=que[p++];
for(int i=0;i<n;i++)
{
if(pre[i]==-1&&cap[t][i]-flow[t][i]>0)
{
pre[i]=t;
que[q++]=i;
d[i]=min(d[t],cap[t][i]-flow[t][i]);
}
}
}
if(pre[sink]==-1) break;
for(int i=sink;i!=source;i=pre[i])
{
flow[pre[i]][i]+=d[sink];
flow[i][pre[i]]-=d[sink];
}
}
t=0;
for(int i=0;i<n;i++)
t+=flow[source][i];
return t;
}
}ek;
int main()
{
int t,n,m,cas=1;
cin>>t;
while (t--) {
cin>>n>>m;
ek.init(n+1);
int a,b,c;
for(int i=0;i<m;i++)
{
cin>>a>>b>>c;
ek.addcap(a,b,c);
}
cout<<"Case "<<cas++<<": ";
cout<<ek.solve(1, n)<<endl;
}
return 0;
}