标签:
flyer.in
输出文件:flyer.out
简单对比1 #include<vector> 2 #include<iostream> 3 using namespace std; 4 #include<cstdio> 5 #include<cstring> 6 #define N 110 7 bool visit[N]={false}; 8 int n,n1; 9 struct Edge{ 10 int v,last; 11 }; 12 int m=-1,head[N],Link[N]; 13 vector<Edge>edge; 14 void add_edge(int u,int v) 15 { 16 Edge e; 17 e.v=v; 18 e.last=head[u]; 19 head[u]=++m; 20 edge.push_back(e); 21 } 22 void input() 23 { 24 scanf("%d%d",&n,&n1); 25 int u,v; 26 while(scanf("%d%d",&u,&v)==2) 27 { 28 add_edge(u,v); 29 } 30 } 31 bool xylfind(int k) 32 { 33 for(int l=head[k];l!=-1;l=edge[l].last) 34 { 35 if(!visit[edge[l].v]) 36 { 37 visit[edge[l].v]=true; 38 if(!Link[edge[l].v]||xylfind(Link[edge[l].v])) 39 { 40 Link[edge[l].v]=k; 41 return true; 42 } 43 } 44 } 45 return false; 46 } 47 int main() 48 { 49 freopen("flyer.in","r",stdin); 50 freopen("flyer.out","w",stdout); 51 memset(head,-1,sizeof(head)); 52 input(); 53 int ans=0; 54 for(int i=1;i<=n1;++i) 55 { 56 memset(visit,false,sizeof(visit)); 57 if(xylfind(i)) ans++; 58 } 59 printf("%d\n",ans); 60 fclose(stdin); 61 fclose(stdout); 62 return 0; 63 }
标签:
原文地址:http://www.cnblogs.com/c1299401227/p/5654515.html