套模板很好的题?

#include<bits/stdc++.h>
using namespace std; const int N=2e2+10;
const int M=4e4+10; struct asd{
int to;
int next;
};
asd q[M];
int head[M],tol;
int n,m;
int col[N]; void add(int u,int v)
{
q[tol].to=v;
q[tol].next=head[u];
head[u]=tol++;
} void init()
{
tol=0;
memset(head,-1,sizeof(head)); } int cy[N];
bool vis[N];
bool Find(int u)
{
for(int i=head[u];i!=-1;i=q[i].next)
{
int v=q[i].to;
if(!vis[v])
{
vis[v]=1;
if(cy[v]==-1||Find(cy[v]))
{
cy[v]=u;
return true;
}
}
}
return false;
} bool Judge(int s)
{
queue<int>que;
col[s]=0;
que.push(s);
while(!que.empty())
{
int u=que.front();que.pop();
for(int i=head[u];i!=-1;i=q[i].next)
{
int v=q[i].to;
if(col[v]==-1)
{
col[v]=1-col[u];
que.push(v);
}
else{
if(col[v]==col[u])
return false;
}
}
}
return true;
} int main()
{
while(~scanf("%d%d",&n,&m))
{
int u,v;
init();
while(m--)
{
scanf("%d%d",&u,&v);
add(u,v);
add(v,u);
} int flag=1;
memset(col,-1,sizeof(col));
for(int i=1;i<=n;i++)
{
if(col[i]==-1)
{
if(!Judge(i))
{
flag=0;
break;
}
}
} if(!flag){
puts("No");
continue;
} int ans=0;
memset(cy,-1,sizeof(cy));
for(int i=1;i<=n;i++)
{
memset(vis,0,sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n",ans>>1);
}
return 0;
}

HDU2444 【二分图判定+最大匹配】的更多相关文章

  1. HDU2444(二分图判定+最大匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  2. HDU 2444 The Accomodation of Students 二分图判定+最大匹配

    题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...

  3. HDU2444(KB10-B 二分图判定+最大匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  4. HDU 2444 The Accomodation of Students(二分图判定+最大匹配)

    这是一个基础的二分图,题意比较好理解,给出n个人,其中有m对互不了解的人,先让我们判断能不能把这n对分成两部分,这就用到的二分图的判断方法了,二分图是没有由奇数条边构成环的图,这里用bfs染色法就可以 ...

  5. CF687A. NP-Hard Problem[二分图判定]

    A. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. hdu3729 I'm Telling the Truth (二分图的最大匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS (Java/ ...

  7. POJ 2584 T-Shirt Gumbo (二分图多重最大匹配)

    题意 现在要将5种型号的衣服分发给n个参赛者,然后给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,再给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...

  8. COJ 0578 4019二分图判定

    4019二分图判定 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给定一个具有n个顶点(顶点编号为0,1,… ...

  9. hdoj 3478 Catch(二分图判定+并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3478 思路分析:该问题需要求是否存在某一个时刻,thief可能存在图中没一个点:将该问题转换为图论问题 ...

随机推荐

  1. VMware Workstation 14创建mac-10.12虚拟机详细步骤

     一.VMware和unlocker的下载和安装 链接:https://pan.baidu.com/s/15Z4DqRENt6JdyfJef_VWSw 密码:40vw 1.安装VMware Works ...

  2. eclipse的debug使用(转载)

    出处:http://www.blogjava.net/yxhxj2006/archive/2012/08/30/386621.html 远程Debug: http://blog.sina.com.cn ...

  3. Ubuntu 13.10上用户怎样获得root权限,用户怎样获得永久root权限,假设配置root登录

    一.用户怎样获得root权限: 1. 进入terminal 2. 输入sudo  passwd root   并设置password,提示要你输入两次password.自己设定password,一定要 ...

  4. 【BZOJ3782】上学路线 组合数+容斥+CRT

    [BZOJ3782]上学路线 Description 小C所在的城市的道路构成了一个方形网格,它的西南角为(0,0),东北角为(N,M).小C家住在西南角,学校在东北角.现在有T个路口进行施工,小C不 ...

  5. xorm

    https://github.com/go-xorm/xorm Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3, ...

  6. 2.alert() 函数

    ①alert() 函数在 JavaScript 中并不常用,但它对于代码测试非常方便. <!DOCTYPE html><html><body> <h1> ...

  7. !推荐:下载abap 源代码

    转自http://blog.sina.com.cn/s/blog_4d1570de0100pvhd.html *@------------------------------------------- ...

  8. Linux系统上安装字体

    最近项目中需要控制字体类型,然后就上网查了一下在linux系统上安装字体,在window上和linux上,字体要求一样,都是ttf格式,下面这是window上的字体截图 在linux系统中的/usr/ ...

  9. jquery特效(6)—判断复选框是否选中进行答题提示

    前面有一段时间思想开了小差,跟着师父学习了一段时间才发现差距很大,看来我要奋起直追~\(≧▽≦)/~啦啦啦. 最近公司在做一个项目,需要根据用户选择的选项给出相应的提示,下面来看我写的测试程序的效果: ...

  10. word使用技巧

    word文档左侧显示目录 word2007  选择word的视图,然后选择文档结构图 word中插入当前文档名称或者文档编辑时间 https://stackoverflow.com/questions ...