- 染色法
#include <bits/stdc++.h>
using namespace std;
const int N=10005;
int ne[N],h[N],e[N],idx;
int color[N],n,m;
void add(int a,int b){
e[idx]=b;
ne[idx]=h[a],h[a]=idx++;
}
bool dfs(int x,int c){
color[x]=c;
for(int i=h[x];i!=-1;i=ne[i]){
int j=e[i];
if(!color[e[i]]){
return dfs(j,3-c);
}
else
if(color[j]==c)
return false;
}
return true;
}
int main(){
cin>>n>>m;
memset(h,-1,sizeof h);
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
add(a,b);
}
bool f=true;
for(int i=1;i<=n;i++){
if(!color[i]){
f=dfs(i,1);
}
if(!f)
break;
}
if(f)
cout<<"Yes";
else
cout<<"No";
}
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int ne[N],h[N],e[N],idx;
int match[N],n,m,k;
bool st[N];
void add(int a,int b){
e[idx]=b;
ne[idx]=h[a],h[a]=idx++;
}
bool find(int x)
{
for(int i=h[x];i!=-1;i=ne[i]){
int j=e[i];
if(!st[j]){
st[j]=true;
if(match[j]==0||find(match[j])){
match[j]=x;
return true;
}
}
}
return false;
}
int main(){
cin>>n>>m>>k;
memset(h,-1,sizeof h);
for(int i=0;i<k;i++){
int a,b;
cin>>a>>b;
add(a,b);
}
int res=0;
for(int i=1;i<=n;i++){
if(res>=m)
break;
memset(st,false,sizeof st);
if(find(i))
res++;
}
cout<<res;
return 0;
}