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

【Description】



有n个人,一些人认识另外一些人,选取一个集合,使得集合里的每个人都互相不认识,求该集合中人的最大个数。

【Solution】



最大独立子集问题;

等于节点个数-最小点覆盖.

写之前做一下染色,从0开始写最大匹配.



【NumberOf WA】



0



【Reviw】

【Code】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1000; int n,color[N+10],Try[N+10],pre[N+10];
vector <int> v[2],g[N+10]; void dfs(int x,int c){
color[x] = c;v[c].pb(x);
int len = g[x].size();
rep1(j,0,len-1){
int y = g[x][j];
if (color[y]==-1) dfs(y,1-c);
}
} bool hungary(int x){
int len = g[x].size();
rep1(i,0,len-1){
int y = g[x][i];
if (!Try[y]){
Try[y] = 1;
if ( pre[y]==-1 || hungary(pre[y])){
pre[y] = x;
return true;
}
}
}
return false;
} int main(){
//Open();
//Close();
while (~scanf("%d",&n)){
rep1(i,1,n) g[i].clear();
rep1(i,1,n){
int x,cnt;
scanf("%d: ",&x);
x++;
scanf("(%d)",&cnt);
rep1(j,1,cnt){
int y;
ri(y);
y++;
g[x].pb(y),g[y].pb(x);
}
} rep1(i,0,1) v[i].clear();
ms(color,255);
rep1(i,1,n)
if (color[i]==-1)
dfs(i,0); int len = v[0].size(),ans = 0;
ms(pre,255);
rep1(i,0,len-1){
ms(Try,0);
if (hungary(v[0][i])) ans++;
}
oi(n-ans);puts("");
}
return 0;
}

【hdu 1068】Girls and Boys的更多相关文章

  1. 【HDU 6017】 Girls Love 233 (DP)

    Girls Love 233 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  2. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  3. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  4. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  5. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  6. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  7. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  8. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  9. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

随机推荐

  1. 用 shell 获取本机的网卡名称

    用 shell 获取本机的网卡名称 # 用 shell 获取本机的网卡名称 ls /sys/class/net # 或者 ifconfig | grep "Link" | awk ...

  2. JAVA并发-为现有的线程安全类添加原子方法

    JAVA中有许多线程安全的基础模块类,一般情况下,这些基础模块类能满足我们需要的所有操作,但更多时候,他们并不能满足我们所有的需要.此时,我们需要想办法在不破坏已有的线程安全类的基础上添加一个新的原子 ...

  3. shrio 登录/退出

    身份验证,即在应用中谁能证明他就是他本人.一般提供如他们的身份ID一些标识信息来表明他就是他本人,如提供身份证,用户名/密码来证明. 在shiro中,用户需要提供principals (身份)和cre ...

  4. idea里新建maven项目时,在new module页面,一直显示loading archetype list...

    不知道什么时候开始,在idea里新建maven项目时,在new module页面,一直显示loading archetype list....,导致一直没办法新建.后来我以为是防火墙问题,各种设置还是 ...

  5. BZOJ 4385 单调队列

    思路: 对于每一个r 要找最小的符合条件的l最优 这时候就要找在这个区间中 d长度的和的最大值 用单调队列更新就好了 //By SiriusRen #include <cstdio> #i ...

  6. Android 数据库框架总结,总有一个适合你!

    一:OrmLite 简述: 优点: 1.轻量级:2.使用简单,易上手:3.封装完善:4.文档全面.缺点:1.基于反射,效率较低(本人还没有觉得效率低):2.缺少中文翻译文档 jar包 地址:http: ...

  7. DENON AVR-X510BT 功放设置记录

    http://manuals.denon.com/avrx510bt/ap/zh/index.php 环绕模式  : Direct:直接 Sttereo:立体声 Dolby PL  声音模式 电影 : ...

  8. 紫书 习题 10-44 UVa 11246 ( 容斥原理)

    把k的倍数的删去(k, 2k, 3k--),但是k^2不应该删去,因为k已经删去,所以不存在某个数乘上k之后为k^2 所以k^2可以留下,然后因为有k^2,所以k^3就是k^2的k倍,所以k^3要删去 ...

  9. UINavigationController导航栏按钮设置

    UINavigationController常见属性 1.一般情况下,导航栏上面显示什么内容,由当前栈顶控制器的navigationItem属性决定 * navigationItem.title : ...

  10. UML图和C#

        这段时间学习了楚光明老师解说的C#视频,接触这个学习材料的第一感觉就是老师解说的通俗易懂,非常easy让人去接受:再有就是在学习到UML图和C#的一节时非常有收获,之前自己也学习过UML图的一 ...