B - The Accomodation of Students - hdu 2444(最大匹配)
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN = ; ///rl记录与根节点的关系
int fa[MAXN], rl[MAXN];
int FindFather(int x)
{
int k = fa[x];
if(fa[x] != x)
{
fa[x] = FindFather(fa[x]);
rl[x] = (rl[x]+rl[k]) % ;
} return fa[x];
} int x[MAXN], y[MAXN], nx, N;
bool G[MAXN][MAXN], used[MAXN]; void InIt()
{
nx = ;
memset(G, , sizeof(G));
for(int i=; i<MAXN; i++)
{
fa[i] = i;
x[i] = y[i] = ;
rl[i] = ;
}
}
bool FindOk(int u)
{
for(int i=; i<=N; i++)
{
if(G[u][i] && used[i] == false)
{
used[i] = true;
if(!y[i] || FindOk(y[i]))
{
y[i] = u;
return true;
}
}
} return false;
} int main()
{
int M; while(scanf("%d%d", &N, &M) != EOF)
{
int i, u, v, ok=; InIt(); while(M--)
{
scanf("%d%d", &u, &v);
G[u][v] = G[v][u] = true; int ru = FindFather(u);
int rv = FindFather(v); if(ru == rv && rl[u] == rl[v])
ok = ;
else if(ru != rv)
{
fa[ru] = rv;
rl[ru] = (rl[u]+rl[v]+)%;
}
} if(ok)
printf("No\n");
else
{
for(i=; i<=N; i++)
{
u = FindFather(i);
if(rl[i] == )
x[nx++] = i;
} int ans = ;
for(i=; i<nx; i++)
{
memset(used, false, sizeof(used));
if(FindOk(x[i]) == true)
ans++;
} printf("%d\n", ans);
}
} return ; }
B - The Accomodation of Students - hdu 2444(最大匹配)的更多相关文章
- The Accomodation of Students HDU - 2444(判断二分图 + 二分匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- The Accomodation of Students HDU - 2444 二分图判定 + 二分图最大匹配 即二分图-安排房间
/*655.二分图-安排房间 (10分)C时间限制:3000 毫秒 | C内存限制:3000 Kb题目内容: 有一群学生,他们之间有的认识有的不认识.现在要求把学生分成2组,其中同一个组的人相互不认 ...
- (匹配)The Accomodation of Students --HDU --2444
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2444 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 2444 The Accomodation of Students 二分图判定+最大匹配
题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...
- 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 判断二分图+最大匹配数
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Problem Description There are a group of s ...
- HDU 2444 The Accomodation of Students【二分图最大匹配问题】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2444 题意:首先判断所有的人可不可以分成互不认识的两部分.如果可以分成 ,则求两部分最多相互认识的对数. ...
- HDU 2444 The Accomodation of Students (二分图最大匹配+二分图染色)
[题目链接]:pid=2444">click here~~ [题目大意]: 给出N个人和M对关系,表示a和b认识,把N个人分成两组,同组间随意俩人互不认识.若不能分成两组输出No,否则 ...
- hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)
http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS Me ...
随机推荐
- Python之路,Day10 - 异步IO\数据库\队列\缓存
Python之路,Day9 - 异步IO\数据库\队列\缓存 本节内容 Gevent协程 Select\Poll\Epoll异步IO与事件驱动 Python连接Mysql数据库操作 RabbitM ...
- Android缓存技术
android应用程序中 1. 尽可能的把文件缓存到本地.可以是 memory,cache dir,甚至是放进 SD 卡中(比如大的图片和音视频). 可以设置双重缓冲,较大的图片或者音频放到SD ...
- 【转】JAVA的StringBuffer类
[转]JAVA的StringBuffer类 StringBuffer类和String一样,也用来代表字符串,只是由于StringBuffer的内部实现方式和String不同,所以StringBu ...
- Asp.net中的页面跳转及post数据
/// <summary> /// This method prepares an Html form which holds all data /// in hidden field i ...
- Css3中的响应式布局的应用
Media Queries直译过来就是“媒体查询”,在我们平时的Web页面中head部分常看到这样的一段代码: <link href="css/reset.css" rel= ...
- 在SpringMVC框架下建立Web项目时web.xml到底该写些什么呢?
刚刚初学Spring MVC,却连一个简单的helloworld都搞的懵懵懂懂的,配置文件搞不清,各种文件之间的逻辑关系也不懂,连续看了好些日子的Spring MVC了,今天终于下定决心,每天记录一点 ...
- UVA 10285 - Longest Run on a Snowboard (记忆化搜索+dp)
Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 seconds Memor ...
- chrome扩展,如何阻止浏览自动关闭桌面通知.
(!!!!以前的好用的, 现在不行了~) 做chrome扩展桌面通知, 可能不想让浏览器自动关闭某个重要的桌面通知.那就不要使用 chrome.notifications.create 可以用 Web ...
- Log4Net使用指南(转)
转自:http://www.cnblogs.com/dragon/archive/2005/03/24/124254.html 声明:本文内容主要译自Nauman Leghari的Using log4 ...
- js实现输入验证码
html部分: <div> <input type="text" id="input" /> <input type=" ...