HDU2444 【二分图判定+最大匹配】
套模板很好的题?
#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 【二分图判定+最大匹配】的更多相关文章
- HDU2444(二分图判定+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 2444 The Accomodation of Students 二分图判定+最大匹配
题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...
- HDU2444(KB10-B 二分图判定+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 2444 The Accomodation of Students(二分图判定+最大匹配)
这是一个基础的二分图,题意比较好理解,给出n个人,其中有m对互不了解的人,先让我们判断能不能把这n对分成两部分,这就用到的二分图的判断方法了,二分图是没有由奇数条边构成环的图,这里用bfs染色法就可以 ...
- CF687A. NP-Hard Problem[二分图判定]
A. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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/ ...
- POJ 2584 T-Shirt Gumbo (二分图多重最大匹配)
题意 现在要将5种型号的衣服分发给n个参赛者,然后给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,再给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能 ...
- COJ 0578 4019二分图判定
4019二分图判定 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给定一个具有n个顶点(顶点编号为0,1,… ...
- hdoj 3478 Catch(二分图判定+并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3478 思路分析:该问题需要求是否存在某一个时刻,thief可能存在图中没一个点:将该问题转换为图论问题 ...
随机推荐
- cookie、session及实现记住密码,自动登录
在登录帐号.密码框下,有三种帐号登录模式可供选择,用户可根据自己的具体情况选择其中一种适合自己的模式. 1.网吧模式:勾选网吧模式后,登录的帐号会在歪歪注销/退出的时候自动清除,不会留在登录框中,可以 ...
- 在XP上安装VS2002
在2002 年,随着 .NET 口号的提出与 Windows XP/Office XP 的公布,微软公布了 Visual Studio .NET(内部版本为 7.0). 使用VS2002+Object ...
- 2016/07/07 mymps(蚂蚁分类信息/地方门户系统)
mymps(蚂蚁分类信息/地方门户系统)是一款基于php mysql的建站系统.为在各种服务器上架设分类信息以及地方门户网站提供完美的解决方案. mymps,整站生成静态,拥有世界一流的用户体验,卓越 ...
- Hibernate基础知识介绍
一.什么是Hibernate? Hibernate,翻译过来是冬眠的意思,其实对于对象来说就是持久化.持久化(Persistence),即把数据(如内存中的对象)保存到可永久保存的存储设备中(如磁盘) ...
- Struts2访问Servlet API的三种方式
有时我们需要用到Request, Response, Session,Page, ServletContext这些我们以前常用的对象,那么在Struts2中怎么样使用到这些对象呢,通常有三种方式. * ...
- delphi android 录像(使用了JMediaRecorder,MediaRecorder的使用方法)
delphi xe系列自带的控件都无法保存录像,经网友帮忙,昨天终于实现了录像功能(但有个问题是录像时无画面显示),程序主要使用了JMediaRecorder,MediaRecorder的使用方法可参 ...
- ubuntu中使用gensim+word2vec[备忘]
python版本: 2.7.12 0. 安装python和pip 1. 用pip依次安装: numpy, cython,scipy,pattern,word2vec 五个工具包 2. 用pip安装ge ...
- HDU3666 THE MATRIX PROBLEM (差分约束+取对数去系数)(对退出情况存疑)
You have been given a matrix C N*M, each element E of C N*M is positive and no more than 1000, The p ...
- 「CQOI2007」「BZOJ1260」涂色paint (区间dp
1260: [CQOI2007]涂色paint Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 2057 Solved: 1267[Submit][St ...
- 自己实现c++中string 类
class String { public: String(const char *str = NULL);// 普通构造函数 String(const String &other);// 拷 ...