Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1695 Accepted Submission(s): 686
6 3 3 1 1 1 2 1 3 2 1 2 3 3 1 0
3
#include <iostream> #include <vector> using namespace std; #define N 1000 vector< vector<int> > map; int mark[N]; bool flag[N]; int nm; int dfs(int pos) { int i,tp,pre; int len=map[pos].size(); for(i=0;i<len;i++) { tp=map[pos][i]; if(!flag[tp]) { flag[tp]=true; pre=mark[tp]; mark[tp]=pos; if(pre==-1 || dfs(pre)) return true; mark[tp]=pre; } } return false; } int main() { int t,n,m,i,num,x,y; while (scanf("%d",&t),t) { num=0; scanf("%d%d",&n,&m); nm=n+m; memset(mark,-1,sizeof(mark)); map.clear(); map.resize(nm+10); while (t--) { scanf("%d%d",&x,&y); map[x].push_back(y); } for(i=1;i<=n;i++) { memset(flag,0,sizeof(flag)); if(dfs(i)) num++; } printf("%d/n",num); } return 0; }