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可能存在图中没一个点:将该问题转换为图论问题 ...
随机推荐
- EasyDarwin开源流媒体项目
本文转自EasyDarwin CSDN官方博客:http://blog.csdn.net/easydarwin EasyDarwin是由国内开源流媒体团队维护和迭代的一整套开源流媒体视频平台框架,从2 ...
- Struts2访问Servlet API的三种方式
有时我们需要用到Request, Response, Session,Page, ServletContext这些我们以前常用的对象,那么在Struts2中怎么样使用到这些对象呢,通常有三种方式. * ...
- jsp页面中文乱码解决方案
一.JSP页面中文乱码 在JSP页面中,中文显示乱码有两种情况:一种是HTML中的中文乱码,另一种是在JSP中动态输出的中文乱码. 先看一个JSP程序: <%@ page language=&q ...
- Red Black Tree java.util.TreeSet
https://docs.oracle.com/javase/9/docs/api/java/util/SortedMap.html public interface SortedMap<K,V ...
- Redis(一)基础数据结构
1.目录 Redis 基础数据结构 string (字符串) list (列表) hash (字典) set (集合) zset (集合) 容器型数据结构的通用规则 过期时间 2.Redis 基础数据 ...
- aop学习总结二------使用cglib动态代理简单实现aop功能
aop学习总结二------使用cglib动态代理简单实现aop功能 模拟业务需求: 1.拦截所有业务方法 2.判断用户是否有权限,有权限就允许用户执行业务方法,无权限不允许用户执行业务方法 (判断是 ...
- [bzoj 1449] 球队收益(费用流)
[bzoj 1449] 球队收益(费用流) Description Input Output 一个整数表示联盟里所有球队收益之和的最小值. Sample Input 3 3 1 0 2 1 1 1 1 ...
- mac配置apache
http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html 用自带的 sudo apachectl -v sudo apachectl ...
- hdu 1004 Let the Balloon Rise 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...
- im资源
https://github.com/oikomi/FishChatServer https://github.com/subrosa-io https://github.com/WhisperSys ...