http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=137

http://poj.org/problem?id=1466

题目大意:

n个学生,他们中有的有关系,有的没有关系,求最多可以取出几个人,使得他们之间没有关系。

思路:

复制别人的。。。。。

最大独立集问题:在N个点的图G中选出m个点,使这m个点两两之间没有边.求m最大值.如果图G满足二分图条件,则可以用二分图匹配来做.最大独立集点数 = N - 最大匹配数/2,然后就是匈牙利算法实现了。

  1. #include<cstdio>
  2. #include<cstring>
  3. const int MAXN=500+10;
  4. int res[MAXN],head[MAXN],len;
  5. bool vis[MAXN];
  6. struct edge
  7. {
  8. int to,next;
  9. }e[MAXN*MAXN];
  10.  
  11. void add(int from,int to)
  12. {
  13. e[len].to=to;
  14. e[len].next=head[from];
  15. head[from]=len++;
  16. }
  17.  
  18. bool find(int a)
  19. {
  20. for(int i=head[a];i!=-1;i=e[i].next)
  21. {
  22. int id=e[i].to;
  23. if(!vis[id])
  24. {
  25. vis[id]=true;
  26. if(res[id]==0 || find(res[id]) )
  27. {
  28. res[id]=a;
  29. return true;
  30. }
  31. }
  32. }
  33. return false;
  34. }
  35. int main()
  36. {
  37. int n;
  38. while(~scanf("%d",&n))
  39. {
  40. memset(res,0,sizeof(res));
  41. memset(head,-1,sizeof(head));
  42. len=0;
  43.  
  44. for(int i=0;i<n;i++)
  45. {
  46. int x,cnt;
  47. scanf("%d: (%d)",&x,&cnt);
  48. for(int j=0;j<cnt;j++)
  49. {
  50. int to;
  51. scanf("%d",&to);
  52. add(x,to);
  53. }
  54. }
  55. int ans=0;
  56. for(int i=0;i<n;i++)
  57. {
  58. memset(vis,0,sizeof(vis));
  59. if(find(i)) ans++;
  60. }
  61. printf("%d\n",n-ans/2);
  62. }
  63. }

POJ 1466 Girls and Boys (ZOJ 1137 )最大独立点集的更多相关文章

  1. poj 1466 Girls and Boys(二分图的最大独立集)

    http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submis ...

  2. POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  3. poj 1466 Girls and Boys 二分图的最大匹配

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  4. POJ 1466 Girls and Boys (匈牙利算法 最大独立集)

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10912   Accepted: 4887 D ...

  5. 网络流(最大独立点集):POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...

  6. poj 1466 Girls and Boys (最大独立集)

    链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点, ...

  7. POJ 1466 Girls and Boys(二分图匹配)

    [题目链接] http://poj.org/problem?id=1466 [题目大意] 给出一些人和他们所喜欢的人,两个人相互喜欢就能配成一对, 问最后没有配对的人的最少数量 [题解] 求最少数量, ...

  8. POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题

    有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开 ...

  9. poj 1466 Girls and Boys(二分匹配之最大独立集)

    Description In the second year of the university somebody started a study on the romantic relations ...

随机推荐

  1. 【Henu ACM Round#18 C】Ilya and Sticks

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用cnt[i]记录数字i出现的次数就好. 然后i从1e6逆序到1 如果cnt[i+1]和cnt[i]>0同时成立的话. 那么得 ...

  2. HRBUST 1376 能量项链

    能量项链 Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HRBUST. Original ID: 13 ...

  3. 在resin配置參数实现JConsole远程监控JVM

    在Resin配置參数实现JConsole远程监控JVM 在Resin中配置中配置下列參数,就能够是实现了! <jvm-arg>-Dcom.sun.management.jmxremote& ...

  4. OpenCASCADE Extended Data Exchange - XDE

    OpenCASCADE Extended Data Exchange - XDE eryar@163.com Abstract. OpenCASCADE Data Exchange allows de ...

  5. jquery11源码 animate() : 运动的方法

    { var fxNow, timerId, rfxtypes = /^(?:toggle|show|hide)$/, rfxnum = new RegExp( "^(?:([+-])=|)( ...

  6. FileStream vs/differences StreamWriter?

    https://stackoverflow.com/questions/4963667/filestream-vs-differences-streamwriter What is different ...

  7. css选择器和优先级总结

    本文转自http://www.cnblogs.com/zxjwlh/p/6213239.html CSS三大特性—— 继承. 优先级和层叠. 继承:即子类元素继承父类的样式; 优先级:是指不同类别样式 ...

  8. POJ 3168 排序+扫描

    题意: 思路: 我们可以把每个矩形拆成四条线 与x轴平行的放在一起 与y轴平行的放在一起 排个序 判一判有没有交 有交 则说明不可扩张 统计一下 就可以了 处理的姿势很重要 姿势不对毁一生 //By ...

  9. 闲的无聊写了个很(wu)有(liao)意(dao)思(bao)的程序

    下午机房断网了 闲的无聊,写了个小游戏 忘了sleep在哪个库里了.. 自带变色效果哦 #include<iostream> #include<cstdio> #include ...

  10. golang binarySearch

    func binarySearch(nodes []*node, word Text) (int, bool) { start := end := len(nodes) - // 特例: { // 当 ...