和以前做过的一个二分图颇为相似,以前的是互相不认识的放在一组,这个是互相认识的,本质上是相同的

hdu 2444

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
#define MAXN 202
vector<int>EV[MAXN];
int linker[MAXN];
bool used[MAXN];
int uN;
int matchs[MAXN],cnt[MAXN];
bool dfs(int u)
{
int i;
for(i=;i<EV[u].size();i++)
{
int v=EV[u][i];
if(!used[v])
{
used[v]=true;
if(linker[v]==-||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
}
return false;
}
int hungary()
{
int res=;
int u;
memset(linker,-,sizeof(linker));
for(u=;u<=uN;u++)
{
memset(used,false,sizeof(used));
if(dfs(u)) res++;
}
return res;
}
bool judge(int x,int y) //交叉染色法判断二分图
{
int i;
for(i=;i<EV[x].size();i++)
{
if(cnt[EV[x][i]]==)
{
cnt[EV[x][i]]=-*y;
matchs[EV[x][i]]=true;
if(!judge(EV[x][i],-*y)) return false;
}
else if(cnt[EV[x][i]]==y) return false;
}
return true;
}
bool matched()
{
int i;
memset(matchs,false,sizeof(matchs));
for(i=;i<=uN;i++)
{
if(EV[i].size()&&!matchs[i])
{
memset(cnt,,sizeof(cnt));
cnt[i]=-;
matchs[i]=true;
if(!judge(i,-)) return false;
}
}
return true;
}
int g[MAXN][MAXN];
int main()
{
int m,n;
int i,j;
int u,v;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
while(scanf("%d",&uN)!=EOF)
{
n=uN;
for(i=;i<=uN;i++)
if(EV[i].size()) EV[i].clear();
cl(g);
int id;
for(i=;i<=n;i++)
{
while(scanf("%d",&id)!=EOF&&id)
{
g[i][id]=;
}
}
for(i=;i<=n;i++)
{
for(j=i+;j<=n;j++)
{
if(!g[i][j]||!g[j][i])
{
EV[i].push_back(j);
EV[j].push_back(i);
}
}
}
if(matched())
printf("YES\n");
else printf("NO\n");
}
return ;
}

hdu 4751 2013南京赛区网络赛 二分图判断 **的更多相关文章

  1. hdu 4753 2013南京赛区网络赛 记忆化搜索 ****

    看到范围基本可以想到dp了,处理起来有点麻烦 #include<iostream> #include<cstdio> #include<cstring> #incl ...

  2. hdu 4741 2013杭州赛区网络赛 dfs ***

    起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...

  3. hdu 4739 2013杭州赛区网络赛 寻找平行坐标轴的四边形 **

    是平行坐标轴的,排个序搞一下就行了,卧槽,水的不行 如果不是平行的,则需要按照边长来判断

  4. hdu 4738 2013杭州赛区网络赛 桥+重边+连通判断 ***

    题意:有n座岛和m条桥,每条桥上有w个兵守着,现在要派不少于守桥的士兵数的人去炸桥,只能炸一条桥,使得这n座岛不连通,求最少要派多少人去. 处理重边 边在遍历的时候,第一个返回的一定是之前去的边,所以 ...

  5. hdu 4731 2013成都赛区网络赛 找规律

    题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举

  6. hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***

    新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...

  7. hdu 4035 2011成都赛区网络赛E 概率dp ****

    太吊了,反正我不会 /* HDU 4035 dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点 ...

  8. hdu 4412 2012杭州赛区网络赛 期望

    虽然dp方程很好写,就是这个期望不知道怎么求,昨晚的BC也是 题目问题抽象之后为:在一个x坐标轴上有N个点,每个点上有一个概率值,可以修M个工作站, 求怎样安排这M个工作站的位置,使得这N个点都走到工 ...

  9. hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***

    题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙,          每个逮捕队伍在每个城市可以选 ...

随机推荐

  1. vim常用命令(iOS)

    iOS下vim的使用: vim 的三种模式: .一般模式(默认) .插入模式(写文字) .命令行模式(保存) 各种模式的功能区分如下: .一般模式:控制屏幕光标的移动,字符和光标的删除,移动复制某区段 ...

  2. JQuery知识点链接

    1.深入理解jQuery插件开发                      http://learn.jquery.com/plugins/basic-plugin-creation/ 2.jQuer ...

  3. 【leetcode】Word Search

    Word Search Given a 2D board and a word, find if the word exists in the grid. The word can be constr ...

  4. struts2 模型驱动

    public class User3Action extends ActionSupport implements ModelDriven<User> { private User use ...

  5. android打电话的小程序

    主要使用了Intent以及uses-permission标签. call.rar 下载后直接导入项目

  6. IEEE802.15.4 部分无线收发芯片比较

    见下表:   TI(CC2530&CC2520) ST(STM32W108) Atmel(AT86RF231) 功耗(发送功率0DB) 30mA 31mA 14mA 是否提供手册 提供 不提供 ...

  7. 【leetcode】 Letter Combinations of a Phone Number(middle)

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  8. 【linux】学习7

    鸟哥 22章内容 单个源代码编译运行 设有一个hello.c 可以用下面方式运行 生成可执行文件a.out [localhost scripts]$ gcc hello.c [localhost sc ...

  9. cuda 初学大全

    转自:http://blog.csdn.net/augusdi/article/details/12529331 cuda 初学大全 1 硬件架构CUDA编程中,习惯称CPU为Host,GPU为Dev ...

  10. 重拾smslib

    http://www.tuicool.com/articles/mm2yQrN http://blog.csdn.net/ll136078/article/details/8737348 http:/ ...