#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <cstdlib>
#include <limits.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#define LL long long
#define MIN -99999999
#define MAX 99999999
#define pii pair<int ,int>
#define bug cout<<"here!!"<<endl
#define PI acos(-1.0)
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define eps 1e-8
#define N 122
int match[N];
bool vis[N];
int g[N][N];
int n;
bool sear(int s){
int i,j;
for(i=1;i<=n;i++){
if(g[i][s] && !vis[i]){
vis[i] = 1;
if(match[i] == 0 || sear(match[i])){
match[i] = s;
return true;
}
}
}
return false;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int m;
scanf("%d%d",&n,&m);
int i,j;
int a,b;
memset(g,0,sizeof(g));
memset(match,0,sizeof(match));
while(m--){
scanf("%d%d",&a,&b);
g[a][b] = 1;
}
int cnt = 0;
for(i=1;i<=n;i++){
memset(vis,0,sizeof(vis));
if(sear(i))cnt++;
}
printf("%d\n",n-cnt);
}
return 0;
}
【最小路径覆盖模板题】POJ 1422
最新推荐文章于 2022-03-31 09:55:23 发布