(匹配)The Accomodation of Students --HDU --2444
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2444
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82834#problem/B
题意:
有n个学生,有m对人是认识的,每一对认识的人能分到一间房,问能否把n个学生分成两部分,每部分内的学生互不认识,而两部分之间的学生认识。如果可以分成两部分,就算出房间最多需要多少间,否则就输出No。
朋友的朋友不是朋友,r代表他们之间的关系
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 205
#define INF 0x3f3f3f3f struct node {int v, next;}e[N]; int n, m, p[N], used[N], Head[N], nx, bnt, f[N], r[N], G[N][N], x[N]; int FindFather(int x)
{
int k = f[x];
if(f[x]!=x)
{
f[x] = FindFather(f[x]);
r[x] = (r[x] + r[k])%;
}
return f[x];
} int Find(int u)
{
for(int i=; i<=n; i++)
{
if(!used[i] && G[u][i])
{
used[i]=;
if(!p[i] || Find(p[i]))
{
p[i] = u;
return true;
}
}
}
return false;
} int main()
{
while(scanf("%d%d", &n, &m)!=EOF)
{
int i, ans=, u, v; bnt = nx = ;
memset(G, , sizeof(G));
memset(p, , sizeof(p));
memset(used, , sizeof(used));
memset(x, , sizeof(x));
for(i=; i<=n; i++)
{
f[i] = i;
r[i] = ;
} for(i=; i<=m; i++)
{
scanf("%d%d", &u, &v);
G[u][v] = G[v][u] =; int ru = FindFather(u);
int rv = FindFather(v); if(ru==rv && r[u]==r[v])
ans = ;
else if(ru!=rv)
{
f[ru] = rv;
r[ru] = (r[u] + r[v] + ) % ;
}
} if(ans)
printf("No\n");
else
{
for(i=; i<=n; i++)
{
u = FindFather(i);
if(r[i]==)
x[nx++] = i;
} int an=;
for(i=; i<nx; i++)
{
memset(used, , sizeof(used));
if(Find(x[i]))
an++;
} printf("%d\n", an);
}
}
return ;
}
(匹配)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 ( ...
- B - The Accomodation of Students - hdu 2444(最大匹配)
题意:现在有一些学生给你一下朋友关系(不遵守朋友的朋友也是朋友),先确认能不能把这些人分成两组(组内的人要相互不认识),不能分的话输出No(小写的‘o’ - -,写成了大写的WA一次),能分的话,在求 ...
- The Accomodation of Students HDU - 2444 二分图判定 + 二分图最大匹配 即二分图-安排房间
/*655.二分图-安排房间 (10分)C时间限制:3000 毫秒 | C内存限制:3000 Kb题目内容: 有一群学生,他们之间有的认识有的不认识.现在要求把学生分成2组,其中同一个组的人相互不认 ...
- HDOJ 2444 The Accomodation of Students
染色判读二分图+Hungary匹配 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limi ...
- 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(最大匹配 + 二分图判断)
http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS Me ...
- 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 ( ...
随机推荐
- sql查询分析器中显示行号
-- 工具-> -- 选项-> -- 文本编辑器-> -- 所有语言-> -- 常规-> -- 显示-> -- 行号
- 根据条件决定My97DatePicker日期控件弹出的日期格式
代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...
- IntelliJ IDEA教程
http://www.jetbrains.com/help/idea/meet-intellij-idea.html
- intellij idea 的常见配置
1.视图配置 配置好后如下图: 2.修改字体大小 3.编码修改 4.行号显示 5.控制台字体大小调整 File->Settings->Editor->Colors & F ...
- Andriod Studio adb 安装应用
原文链接:https://blog.csdn.net/u014608640/article/details/51833304 下面的命令安装.重新安装和卸载应用程序. 安装:adb -s HT9BYL ...
- \extras\intel\Hardware_Accelerated_Execution_Manager HAXM 未安装导致AndroidStudio新建了模拟器开启不了
之前安装过 bios模式也是正常的.所以按照下面的步骤操作. https://software.intel.com/en-us/android 在这个界面 选择右侧的, 下载后解压到下面图上的路径: ...
- Cookie的Domain属性
Cookie 加了Domain后就写不进去了(不加domain就可以写进去了) 本地测试的时候需要把domain换成localhost cookie跨域的问题,意思就是说A.com下能访问B.com域 ...
- 整合Spring框架和Hibernate框架
-------------------siwuxie095 整合 Spring 框架和 Hibernate 框架 1.导 ...
- 230. Kth Smallest Element in a BST 找到bst中的第k小的元素
[抄题]: Given a binary search tree, write a function kthSmallest to find the kth smallest element in i ...
- js Array Map and Set
Array slice slice()就是对应String的substring()版本,它截取Array的部分元素,然后返回一个新的Array: var arr = ['A', 'B', 'C', ' ...