#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define MAX 200
int g[MAX][MAX],vis[MAX],link[MAX];
int k,n,m,xx;
int dfs(int x){
for(int i = 1;i <= xx;i++){
if(g[x][i] == 1 && vis[i] == 0){
vis[i] = 1;
if(link[i] == -1 || dfs(link[i])){
link[i] = x;
return 1;
}
}
}
return 0;
}
int main(){
int x,y;
scanf("%d",&k);
while(k--){
memset(g,0,sizeof(g));
memset(link,-1,sizeof(link));
scanf("%d%d",&n,&m);
for(int i = 1;i <= m;i++){
scanf("%d%d",&x,&y);
g[x][y] = 1;
}
xx = n>m?n:m;
int ans = 0;
for(int i = 1;i <= xx;i++){
memset(vis,0,sizeof(vis));
if(dfs(i)) ans++;
}
n -= ans;
cout<<n<<endl;
}
return 0;
}
POJ 1422 Air Raid
最新推荐文章于 2021-01-11 23:10:18 发布