POJ 1466 Girls and Boys (ZOJ 1137 )最大独立点集
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,然后就是匈牙利算法实现了。
- #include<cstdio>
- #include<cstring>
- const int MAXN=500+10;
- int res[MAXN],head[MAXN],len;
- bool vis[MAXN];
- struct edge
- {
- int to,next;
- }e[MAXN*MAXN];
- void add(int from,int to)
- {
- e[len].to=to;
- e[len].next=head[from];
- head[from]=len++;
- }
- bool find(int a)
- {
- for(int i=head[a];i!=-1;i=e[i].next)
- {
- int id=e[i].to;
- if(!vis[id])
- {
- vis[id]=true;
- if(res[id]==0 || find(res[id]) )
- {
- res[id]=a;
- return true;
- }
- }
- }
- return false;
- }
- int main()
- {
- int n;
- while(~scanf("%d",&n))
- {
- memset(res,0,sizeof(res));
- memset(head,-1,sizeof(head));
- len=0;
- for(int i=0;i<n;i++)
- {
- int x,cnt;
- scanf("%d: (%d)",&x,&cnt);
- for(int j=0;j<cnt;j++)
- {
- int to;
- scanf("%d",&to);
- add(x,to);
- }
- }
- int ans=0;
- for(int i=0;i<n;i++)
- {
- memset(vis,0,sizeof(vis));
- if(find(i)) ans++;
- }
- printf("%d\n",n-ans/2);
- }
- }
POJ 1466 Girls and Boys (ZOJ 1137 )最大独立点集的更多相关文章
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- poj 1466 Girls and Boys 二分图的最大匹配
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- POJ 1466 Girls and Boys (匈牙利算法 最大独立集)
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 10912 Accepted: 4887 D ...
- 网络流(最大独立点集):POJ 1466 Girls and Boys
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...
- poj 1466 Girls and Boys (最大独立集)
链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点, ...
- POJ 1466 Girls and Boys(二分图匹配)
[题目链接] http://poj.org/problem?id=1466 [题目大意] 给出一些人和他们所喜欢的人,两个人相互喜欢就能配成一对, 问最后没有配对的人的最少数量 [题解] 求最少数量, ...
- POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开 ...
- poj 1466 Girls and Boys(二分匹配之最大独立集)
Description In the second year of the university somebody started a study on the romantic relations ...
随机推荐
- 【Henu ACM Round#18 C】Ilya and Sticks
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用cnt[i]记录数字i出现的次数就好. 然后i从1e6逆序到1 如果cnt[i+1]和cnt[i]>0同时成立的话. 那么得 ...
- HRBUST 1376 能量项链
能量项链 Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HRBUST. Original ID: 13 ...
- 在resin配置參数实现JConsole远程监控JVM
在Resin配置參数实现JConsole远程监控JVM 在Resin中配置中配置下列參数,就能够是实现了! <jvm-arg>-Dcom.sun.management.jmxremote& ...
- OpenCASCADE Extended Data Exchange - XDE
OpenCASCADE Extended Data Exchange - XDE eryar@163.com Abstract. OpenCASCADE Data Exchange allows de ...
- jquery11源码 animate() : 运动的方法
{ var fxNow, timerId, rfxtypes = /^(?:toggle|show|hide)$/, rfxnum = new RegExp( "^(?:([+-])=|)( ...
- FileStream vs/differences StreamWriter?
https://stackoverflow.com/questions/4963667/filestream-vs-differences-streamwriter What is different ...
- css选择器和优先级总结
本文转自http://www.cnblogs.com/zxjwlh/p/6213239.html CSS三大特性—— 继承. 优先级和层叠. 继承:即子类元素继承父类的样式; 优先级:是指不同类别样式 ...
- POJ 3168 排序+扫描
题意: 思路: 我们可以把每个矩形拆成四条线 与x轴平行的放在一起 与y轴平行的放在一起 排个序 判一判有没有交 有交 则说明不可扩张 统计一下 就可以了 处理的姿势很重要 姿势不对毁一生 //By ...
- 闲的无聊写了个很(wu)有(liao)意(dao)思(bao)的程序
下午机房断网了 闲的无聊,写了个小游戏 忘了sleep在哪个库里了.. 自带变色效果哦 #include<iostream> #include<cstdio> #include ...
- golang binarySearch
func binarySearch(nodes []*node, word Text) (int, bool) { start := end := len(nodes) - // 特例: { // 当 ...