题意分析
直接二分图匹配就好了
代码总览
#include<bits/stdc++.h>
using namespace std;
const int nmax = 1000 + 10;
const int INF = 0x3f3f3f3f;
bool mp[nmax][nmax];
bool visit[nmax];
int cx[nmax], cy[nmax];
int n,m,ans = 0;
bool findpath(int u){
for(int i = 0;i<n;++i){
if(mp[u][i] && !visit[i]){
visit[i] = 1;
if(!cy[i] || findpath(cy[i])){
cx[u] = i;
cy[i] = u;
return 1;
}
}
}
return 0;
}
void getans(){
for(int i = 1;i<=m;++i){
memset(visit,0,sizeof visit);
if(findpath(i)) ans ++;
else return;
}
}
int main(){
scanf("%d %d",&n,&m);
int a,b;
for(int i = 1;i<=m;++i){
scanf("%d %d",&a,&b);
mp[i][a] = mp[i][b] = 1;
}
getans();
printf("%d\n",ans);
return 0;
}