Sample Input
4
0:(1) 1
1:(2) 2 3
2:(0)
3:(0)
5
3:(3) 1 4 2
1:(1) 0
2:(0)
0:(0)
4:(0)
Sample Output
1
2
最小点覆盖=最大匹配数
水题,懒的拍了
1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<string.h> 5 #include<vector> 6 using namespace std; 7 const int MAXN=1505; 8 int linker[MAXN]; 9 bool used[MAXN]; 10 vector<int>map[MAXN]; 11 int uN; 12 bool dfs(int u) 13 { 14 for(int i=0;i<map[u].size();i++) 15 { 16 if(!used[map[u][i]]) 17 { 18 used[map[u][i]]=true; 19 if(linker[map[u][i]]==-1||dfs(linker[map[u][i]])) 20 { 21 linker[map[u][i]]=u; 22 return true; 23 } 24 } 25 } 26 return false; 27 } 28 int hungary() 29 { 30 int u; 31 int res=0; 32 memset(linker,-1,sizeof(linker)); 33 for(u=0;u<uN;u++) 34 { 35 memset(used,false,sizeof(used)); 36 if(dfs(u)) res++; 37 } 38 return res; 39 } 40 int main() 41 { 42 int u,k,v; 43 int n; 44 while(scanf("%d",&n)!=EOF) 45 { 46 for(int i=0;i<MAXN;i++) 47 map[i].clear(); 48 for(int i=0;i<n;i++) 49 { 50 scanf("%d:(%d)",&u,&k); 51 while(k--) 52 { 53 scanf("%d",&v); 54 map[u].push_back(v); 55 map[v].push_back(u); 56 } 57 } 58 uN=n; 59 printf("%d ",hungary()/2); 60 } 61 return 0; 62 }