标签:des c style class blog code
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 6520 | Accepted: 3877 |
Description
Input
Output
Sample Input
2 4 3 3 4 1 3 2 3 3 3 1 3 1 2 2 3
Sample Output
2 1
Source
1 //152K 0MS C++ 965B 2014-06-03 12:26:21 2 #include<iostream> 3 #include<vector> 4 #define N 205 5 using namespace std; 6 vector<int>V[N]; 7 int vis[N]; 8 int match[N]; 9 int n; 10 int dfs(int u) 11 { 12 for(int i=0;i<V[u].size();i++){ 13 int v=V[u][i]; 14 if(!vis[v]){ 15 vis[v]=1; 16 if(match[v]==-1 || dfs(match[v])){ 17 match[v]=u; 18 return 1; 19 } 20 } 21 } 22 return 0; 23 } 24 int hungary() 25 { 26 memset(match,-1,sizeof(match)); 27 int ret=0; 28 for(int i=1;i<=n;i++){ 29 memset(vis,0,sizeof(vis)); 30 ret+=dfs(i); 31 } 32 return ret; 33 } 34 int main(void) 35 { 36 int t,m,a,b; 37 scanf("%d",&t); 38 while(t--) 39 { 40 scanf("%d",&n); 41 for(int i=0;i<=n;i++) V[i].clear(); 42 scanf("%d",&m); 43 while(m--){ 44 scanf("%d%d",&a,&b); 45 V[a].push_back(b); 46 //V[b].push_back(a); 47 } 48 printf("%d\n",n-hungary()); 49 } 50 return 0; 51 }
poj 1422 Air Raid (二分匹配),布布扣,bubuko.com
标签:des c style class blog code
原文地址:http://www.cnblogs.com/GO-NO-1/p/3765526.html