Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=1068

View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 using namespace std;
 4 
 5 const int N=1500;
 6 int g[N][N],n;
 7 int mat[N],vis[N];
 8 bool match(int u)
 9 {
10     for(int v=0;v<n;v++)
11         if(g[u][v] && !vis[v])
12         {
13             vis[v]=1;
14             if(mat[v]==-1 || match(mat[v]))
15             {
16                 mat[v]=u;
17                 return 1;
18             }
19         }
20     return 0;
21 }
22 int main()
23 {
24     while(~scanf("%d",&n))
25     {
26         memset(g,0,sizeof(g));
27         int u,v,m;
28         for(int i=0;i<n;i++)
29         {
30             scanf("%d: (%d)",&u,&m);
31             for(int j=0;j<m;j++)
32             {
33                 scanf("%d",&v);
34                 g[u][v]=1;
35             }
36         }
37         int cnt=0;
38         memset(mat,-1,sizeof(mat));
39         for(int i=0;i<n;i++)
40         {
41             memset(vis,0,sizeof(vis));
42             if(match(i)) cnt++;
43         }
44         printf("%d\n",n-cnt/2);
45     }
46     return 0;
47 }

 

posted on 2012-04-17 08:35  Qiuqiqiu  阅读(195)  评论(0编辑  收藏  举报