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可能存在图中没一个点:将该问题转换为图论问题 ...
随机推荐
- warez世界顶级压缩作品网站
http://www.pouet.net/ warez世界顶级压缩作品网站
- libcurl以get方式请求服务器端文件
static size_t callbackfunction(void *ptr, size_t size, size_t nmemb, void* userdata){ FILE* strea ...
- java 内部类(转)
原文: http://www.cnblogs.com/nerxious/archive/2013/01/24/2875649.html 内部类不是很好理解,但说白了其实也就是一个类中还包含着另外一个类 ...
- ubuntu:undefined reference to `snd_pcm_open'
这几天在做一个局域网的对讲机和广播系统. 需要用到alsa的库来进行音频采集和播放. 但是在编译程序的时候有个比较奇怪的问题. undefined reference to `snd_pcm_open ...
- linux应用之php开发环境lamp搭建(centos)
搭建linux+apache+mysql+php环境 1.安装apache: yum install httpd httpd-devel 启动apache: /etc/init.d/httpd ...
- Mac开发快速入门
初次接触mac开发,发现国内相关资料少得可怜,于是写下这篇文章,作为学习记录.Mac应用开发也是使用Objective-C进行开发的,所以从iOS转Mac并不困难,很多东西都一样. 本文以一个登录界面 ...
- WPF Combo box 获取选择的Tag
string str1 = ((ComboBoxItem)this.cboBoxRate1553B.Items[this.cboBoxRate1553B.SelectedIndex]).Tag.ToS ...
- Java 高阶 —— native 关键字与 JNI
1. JNI Java中JNI的使用详解第一篇:HelloWorld JNI:Java Native Interface,Java 本地接口(或本机接口,更具体地讲叫本地编程接口),其提供了若干 AP ...
- mpvue微信小程序分包
## 微信小程序分包(mpvue) 使用mpvue分包示例:1.下载vue脚手架(先有node环境,v8.12.0) npm install -g vue-cli 2.先用vue初始化一个mpvue小 ...
- CodeForces669E:Little Artem and Time Machine(CDQ分治)(或者用map+树状数组优美地解决)
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of cour ...