HDU 2444 The Accomodation of Students(判断是否可图 + 二分图)
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define maxn 500
bool G[maxn][maxn], vis[maxn];
int color[maxn], P[maxn];///黑白染色 -1 黑色 1 白色
int n, m; bool DFS(int u,int c)///判断是否是二分图,黑白染色
{
color[u] = c;
for(int i=; i<=n; i++)
{
if(!G[u][i] )
continue;
if(color[i] == )
{
if( DFS(i, -c) )
continue;
return false;
}
else if(color[i] + color[u])
return false; }
return true;
}
bool Find(int u)
{
for(int i=; i<=n; i++)
{
if(G[u][i] && !vis[i])
{
vis[i] = true;
if(P[i] == - || Find(P[i]))
{
P[i] = u;
return true;
}
}
}
return false;
} int solve()
{
bool ok;
for(int i=; i<=n; i++)
{
if(color[i] == )
ok = DFS(i, );
if(ok == false)
return -;
} int ans = ;
for(int i=; i<=n; i++)
{
memset(vis, false, sizeof(vis));
if(color[i] && Find(i))
ans ++;
}
return ans;
} int main()
{
while(scanf("%d %d",&n, &m) != EOF)
{
int a, b;
memset(G, false, sizeof(G));
memset(P, -, sizeof(P));
memset(color, , sizeof(color)); for(int i=; i<m; i++)
{
scanf("%d %d",&a, &b);
G[a][b] = true;
}
int ans = solve(); if(ans == -)
puts("No");
else
printf("%d\n", ans );
}
return ;
}
HDU 2444 The Accomodation of Students(判断是否可图 + 二分图)的更多相关文章
- hdu 2444 The Accomodation of Students 判断二分图+二分匹配
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 2444 The Accomodation of Students(判断二分图+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 2444 The Accomodation of Students (判断二分图,最大匹配)
The Accomodation of StudentsTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- hdu 2444 The Accomodation of Students 判断是否构成二分图 + 最大匹配
此题就是求最大匹配.不过需要判断是否构成二分图.判断的方法是人选一点标记为红色(0),与它相邻的点标记为黑色(1),产生矛盾就无法构成二分图.声明一个vis[],初始化为-1.通过深搜,相邻的点不满足 ...
- HDU 2444 The Accomodation of Students(推断是否是二分图)
题目链接 题意:n个学生,m对关系,每一对互相认识的能住一个房间.问否把这些学生分成两组,要求每组的学生都互不认识.求最多须要多少个房间. 能否分成两组?也就是说推断是不是二分图,推断二分图的办法,用 ...
- HDU 2444 The Accomodation of Students 二分图判定+最大匹配
题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...
- hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)
http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS Me ...
- (hdu)2444 The Accomodation of Students 判断二分图+最大匹配数
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Problem Description There are a group of s ...
- hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- leetcode第一刷_Construct Binary Tree from Preorder and Inorder Traversal
构造方式跟中序与后序全然一样,并且一般都习惯正着来,所以更简单. 代码是之前写的,没实用库函数,不应该. TreeNode *buildIt(vector<int> &preord ...
- 用htaccess进行访问控制(转)
1. 文件访问控制 利用 httpd.conf 中的 Order.Files 及 FilesMatch 命令实现的访问控制可以满足大部分要求,但是当用户被拒绝时,他们看到的是硕大的“403 Forbi ...
- Using SSL Certificates with HAProxy--reference
原文地址:http://serversforhackers.com/editions/2014/07/29/haproxy-ssl-termation-pass-through/ Overview I ...
- Linux基础系列—Linux体系结构和Linux内核结构
/** ****************************************************************************** * @author 暴走的小 ...
- Strust2 <c:forEach> 循环控制标签
<c:forEach>为循环控制标签 语法:迭代一集合对象中的所有成员 <c:forEach [var="varName"] items="collec ...
- maven 启动忽略test
两种方法 1,--命令 mvn install -Dmaven.test.skip=true 2.pom.xml 文件 在tomcat 下面的pom.xml 文件里面加上如下 <!-- ski ...
- java常见错误的列表
ava常见错误列表: 找不到符号(symbol) 类X是public的,应该被声明在名为X.java的文件中 缺失类.接口或枚举类型 缺失X 缺失标识符 非法的表达式开头 类型不兼容 非法的方法声明; ...
- application/json IE 兼容问题
由于IE系列浏览器把application/json响应视为文件,并尝试下载在网上看了一下,大致了解,只要修改返回的内容的类型(ContentType)即可解决问题. 由于ajax请求,返回类型默认就 ...
- MVC部署出现HTTP 404 错误
asp.net mvc部署出现问题,http错误404.0,报错如下图: 在网上找了好多方法都不行.最后我的解决方案是: 打好这个补丁就行了http://support.microsoft.com/k ...
- (转)ecshop 后台商品分类添加图片的功能
转之--http://blog.sina.com.cn/s/blog_4696b3760100n5ee.html 1 .首先找到数据表 ecs_category (商品分类表) 添加一 cat_i ...