题目链接
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int N = 103;
int n, m;
vector<int> G[N];
int match[N], st[N];
bool find(int x){
for(int j = 0; j < G[x].size(); j++){
int v = G[x][j];
if(!st[v]){ //每轮只能用一次
st[v] = 1;
if(!match[v] || find(match[v])){ //没有对象或者是能腾出一个对象来
match[v] = x; //那就让她跟x好上
return true;
}
}
}
return false;
}
int main(){
cin >> n>> m;
int u, v;
while(cin>>u>>v){
if(u == -1 && v == -1) break;
G[u].push_back(v);
}
int res = 0;
for(int i = 1; i <= m; i++){
memset(st, 0 ,sizeof(st));
if(find(i)) res++;
}
if(!res) cout<<"No Solution!"<<endl;
else cout<<res<<endl;
return 0;
}