显示代码纯文本
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
bool G[121][121];
int T,n,m,a1,a2,ans,cnt;
int use[121],pre[121];
bool DFS(int x)
{
for(int i=1;i<=n;i++)
{
if(G[x][i]&&!use[i])
{
use[i]=1;
if(pre[i]==0||DFS(pre[i]))
{
pre[i]=x;
return 1;
}
}
}
return 0;
}
int LINYIN()
{
freopen("airraid.in","r",stdin);
freopen("airraid.out","w",stdout);
scanf("%d",&T);
while(T--)
{
ans=0,cnt=0;
memset(G,0,sizeof(G));
memset(use,0,sizeof(use));
memset(pre,0,sizeof(pre));
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&a1,&a2);
G[a1][a2]=1;
}
for(int i=1;i<=n;i++)
{
memset(use,0,sizeof(use));
ans+=DFS(i);
}
printf("%d\n",n-ans);
}
}
int LWH=LINYIN();
int main()
{
;
}