AcWing 379. 二分图
原题链接
简单
作者:
Lemmon_kk
,
2020-07-17 22:57:55
,
所有人可见
,
阅读 536
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 210, M = 30020;
bool d[N][N];
bool st[N];
int n, m;
int match[N];
bool find(int x){
for(int i = 1;i <= n;i ++ )
if(!st[i] && d[x][i]){
st[i] = true;
int t = match[i];
if(!t || find(t)){
match[i] = x;
return true;
}
}
return false;
}
int main(){
cin >> n >> m;
while(m -- ){
int a, b;
cin >> a >> b;
d[a][b] = true;
}
//求传递闭包
for(int k = 1;k <= n;k ++ )
for(int i = 1;i <= n;i ++ )
for(int j = 1;j <= n;j ++ )
d[i][j] |= d[i][k] & d[k][j];
int res = 0;
for(int i = 1;i <= n;i ++ ){
memset(st, 0, sizeof st);
if(find(i)) res ++ ;
}
cout << n - res << endl;
return 0;
}
tql