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 ...
随机推荐
- EventBus 事件总线 原理
原理 一句话描述:register会把当前类中匹配的方法,存入一个map,而post会根据实参去map查找进行反射调用 撇开专业术语,其实EventBus就是在内部[存储]了一堆onEvent开头的方 ...
- ZOJ3527
题意:给你一个有向图,一共N个顶点,且每个顶点只有一个前驱或后继,在顶点上建立圣地,那么就可以获得一个信仰值,如果在这个顶点的后继节点上也建立圣地,那么将改变一定的信仰值,求解能获取的最大信仰值. 思 ...
- jquery获取元素到屏幕底的可视距离
jquery获取元素到屏幕底的可视距离 要打对号的图里的height(我自称为可视高度:滚动条未滑到最底端) 不是打叉图里的到页面底部(滚动条到最底部时的height)(offset().top方法 ...
- 关于html水平垂直居中的一些总结吧
html水平垂直居中 最近遇到很多居中的问题,就花点时间总结了一下放在这里,以后找也方便,0.0~~ 1.居中文本 <div class="wrap"> 我在中间…… ...
- mysql复习增删改查
select * from torder where status='退款申请' UPDATE torder SET `status`='退款申请' WHERE status='等待付款' and i ...
- utils object doesn,t exists中毒后,就删除了.JS文件后台就出现了前面的英文。请问怎么解决
明显是你删了js丢失了函数了...从备份里还原一份.js出来放进去,前台也不能删,如果遇到名字冲突,修改一下名字即可
- Mavne + Spring整合CXF
http://blog.csdn.net/xiongyu777888/article/details/23787615(没毛病) http://blog.csdn.net/hbsong75/artic ...
- JavaScript--赋值表达式(typeof-delete-void)
typeof运算符 typeof是一个一元运算符,操作数可以使任意类型,返回值为操作数类型的一个字符串 一.数字类型,如typeof(1),返回的值就是number.当然这个是常规数字,对于非常规的数 ...
- 关于jQuery表单校验的应用
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- localStorage 的基本使用
① localstorage大小限制在500万字符左右,各个浏览器不一致② localstorage在隐私模式下不可读取③ localstorage本质是在读写文件,数据多的话会比较卡(firefox ...