标签:
思路:傻逼题,裸匹配,当然为了迎合题目写成网络流也是可以的
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<fstream> 5 #define cin fin 6 #define cout fout 7 #define maxn 1000 8 using namespace std; 9 int head[maxn],next[maxn],point[maxn],now,visit[maxn]; 10 int match[maxn]; 11 ofstream fout ("flyer.out"); 12 ifstream fin ("flyer.in"); 13 void add(int x,int y) 14 { 15 next[++now] = head[x]; 16 head[x]=now; 17 point[now] = y; 18 } 19 int dfs(int x) 20 { 21 for(int i=head[x];i;i=next[i]) 22 { 23 int u = point[i]; 24 if(visit[u])continue; 25 visit[u] = 1; 26 if(match[u]==-1 || dfs(match[u])) 27 { 28 match[u] = x; 29 return 1; 30 } 31 } 32 return 0; 33 } 34 int main() 35 { 36 int n,m,ans=0,x,y; 37 cin>>n>>m; 38 while(cin>>x>>y) 39 { 40 add(x,y); 41 } 42 memset(match,-1,sizeof(match)); 43 for(int i=1;i<=m;i++) 44 { 45 memset(visit,0,sizeof(visit)); 46 if(dfs(i))ans++; 47 } 48 cout<<ans<<endl; 49 return 0; 50 }
标签:
原文地址:http://www.cnblogs.com/philippica/p/4699795.html