最小不相交路径覆盖 = 顶点数 - 最大匹配
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 120+5;
const int inf = 1e9;
int n,m;
vector<int>head[MAXN];
bool vis[MAXN];
int match[MAXN];
bool dfs(int u)
{
for(int i = 0,l = head[u].size(); i < l; ++i)
{
int v = head[u][i];
if(!vis[v])
{
vis[v] = 1;
if(match[v] == -1 || dfs(match[v]))
{
match[v] = u;
return 1;
}
}
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
int u,v;
for(int i = 1; i <= n; ++i)head[i].clear();
while(m--)
{
scanf("%d%d",&u,&v);
head[u].push_back(v);
}
fill(match+1,match+1+n,-1);
int ans = n;
for(int i = 1; i <= n; ++i)
{
fill(vis+1,vis+1+n,0);
if(dfs(i))ans--;
}
printf("%d\n",ans);
}
return 0;
}