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 ( ...
随机推荐
- 《Head First 设计模式》学习笔记——工厂模式 + 抽象工厂模式
设计模式 工厂模式:定义一个创建对象的接口,但由子类决定要实例化的是哪一个.工厂方法让类把实例化推迟到子类. 所谓的"决定",并非指模式同意子类本身在执行时做决定,而是指在编写创建 ...
- cocos2d-x项目过程记录(cocos2d-x的新知)
1.给CCMenuItem带上点击参数(这是CCNode的一个属性) CCMenuItem *item = CCMenuItemSprite::create(unselectedPic, select ...
- Java EE 7 / JAX-RS 2.0: Simple REST API Authentication & Authorization with Custom HTTP Header--reference
REST has made a lot of conveniences when it comes to implementing web services with the already avai ...
- linux sysvinit与upstart [转]
linux sysvinit与upstart(1) linux sysvinit与upstart(2) linux sysvinit与upstart(3)
- 2015 南阳ccpc The Battle of Chibi (uestc 1217)
题意:给定一个序列,找出长度为m的严格递增序列的个数. 思路:用dp[i][j]表示长度为i的序列以下标j结尾的总个数.三层for循环肯定超时,首先离散化,离散化之后就可以用树状数组来优化,快速查找下 ...
- 转 - CSS深入理解vertical-align和line-height的基友关系
一.想死你们了 几个星期没有写文章了,好忙好痒:个把月没有写长篇了,好忙好想:半个季度没在文章中唠嗑了,好痒好想. 后面一栋楼有对夫妻在吵架,声音雄浑有力,交锋酣畅淋漓,还以为只有小乡镇才有这架势,哦 ...
- C# 邮件发送注意事项
使用QQ邮箱作为smtp服务器时,遇到 "命令顺序不正确. 服务器响应为: AUTH first..",解决办法: smtpClient.UseDefaultCredentials ...
- 移动Web开发技巧
META相关 1. 添加到主屏后的标题(IOS) <meta name="apple-mobile-web-app-title" content="标题" ...
- java编程思想-泛型思维导图
- Android-SVN
服务器启动svn服务 svnserve -d -r /home/wbp/svn/actia/ 1 .svn 重新定位location , 改变新仓库的uuid , 今天操作SVN Client 发现 ...