1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 7 structEdge8 {9 intFro,to,next;Ten}e[100010]; One intmap[ the][ the]; A BOOLvis[1100]; - inthead[1100]; - intlink[1100]; the intans[ -]; - - intFindintx) - { + for(inti=head[x];i!=-1; i=e[i].next) - { + if(!vis[e[i].to]) A { at intq=link[e[i].to]; -link[e[i].to]=E[i].fro; -vis[e[i].to]=true; - if(q==-1||find (q)) - return 1; -link[e[i].to]=Q; in } - } to return 0; + } - the intMain () * { $ intn,k;Panax Notoginseng while(SCANF ("%d%d", &n,&k)! =EOF) - { the if(n==0&&k==0) + Break; A for(intI=1; i<=n;i++) the { + for(intj=1; j<=n;j++) - { $scanf"%d",&map[i][j]); $ } - } - intTol=0; the for(intI=1; i<= -; i++) - {Wuyi inttmp=0; the intnum=1; - intflag=0; Wumemset (head,-1,sizeof(head)); -memset (link,-1,sizeof(link)); About for(intj=1; j<=n;j++) $ { - for(intt=1; t<=n;t++) - { - if(map[j][t]==i) A { +flag=1; thee[num].fro=J; -e[num].to=T; $e[num].next=Head[j]; thehead[j]=num; thenum++; the } the } - } in if(!flag) the Continue; the for(intj=1; j<=n;j++) About { thememset (Vis,false,sizeof(Vis)); thetmp+=find (j); the } + if(tmp>k) - { theans[tol]=i;Bayitol++; the } the } - if(tol==0) -cout<<-1<<Endl; the Else the { thecout<<ans[0]; the for(intI=1; i<tol;i++) - { thecout<<" "<<Ans[i]; the } thecout<<Endl;94 } the } the return 0; the}
View Code
1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 7 structEdge8 {9 intFro,to,next;Ten}e[10010]; One inthead[510]; A BOOLvis[510]; - intlink[510]; - the intFindintx) - { - for(inti=head[x];i!=-1; i=e[i].next) - { + if(!vis[e[i].to]) - { + intq=link[e[i].to]; Alink[e[i].to]=E[i].fro; atvis[e[i].to]=true; - if(q==-1||find (q)) - return 1; -link[e[i].to]=Q; - } - } in return 0; - } to + intMain () - { the intn,k; * while(SCANF ("%d%d", &n,&k)! =EOF) $ {Panax Notoginseng intans=0; -memset (head,-1,sizeof(head)); the for(intI=1; i<=k;i++) + { Ascanf"%d%d",&e[i].fro,&e[i].to); thee[i].next=Head[e[i].fro]; +head[e[i].fro]=i; - } $memset (link,-1,sizeof(link)); $ for(intI=1; i<=n;i++) - { -memset (Vis,false,sizeof(Vis)); theans+=find (i); - }Wuyicout<<ans<<Endl; the } - return 0; Wu}
View Code
Binary graph matching hdu1498&&poj3041